-
Notifications
You must be signed in to change notification settings - Fork 28
/
CustomErrorControllerConfiguration.java
41 lines (33 loc) · 1.34 KB
/
CustomErrorControllerConfiguration.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package me.chanjar.boot.customerrorcontroller;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.web.ErrorAttributes;
import org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration;
import org.springframework.boot.autoconfigure.web.ErrorViewResolver;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.List;
@Configuration
public class CustomErrorControllerConfiguration {
private final ServerProperties serverProperties;
private final List<ErrorViewResolver> errorViewResolvers;
public CustomErrorControllerConfiguration(ServerProperties serverProperties,
ObjectProvider<List<ErrorViewResolver>> errorViewResolversProvider) {
this.serverProperties = serverProperties;
this.errorViewResolvers = errorViewResolversProvider.getIfAvailable();
}
/**
* 抄的是{@link ErrorMvcAutoConfiguration#basicErrorController(ErrorAttributes)}
*
* @param errorAttributes
* @return
*/
@Bean
public CustomErrorController customErrorController(ErrorAttributes errorAttributes) {
return new CustomErrorController(
errorAttributes,
this.serverProperties.getError(),
this.errorViewResolvers
);
}
}