Java 错误控制程序Howto:Spring boot+;Spring数据休息
使用SpringDataREST的SpringBoot-如何使用自定义错误处理程序。 创建了一个错误控制器,我尝试使用以下代码跳过默认的错误处理程序。 为什么它不起作用Java 错误控制程序Howto:Spring boot+;Spring数据休息,java,spring-boot,spring-data-rest,Java,Spring Boot,Spring Data Rest,使用SpringDataREST的SpringBoot-如何使用自定义错误处理程序。 创建了一个错误控制器,我尝试使用以下代码跳过默认的错误处理程序。 为什么它不起作用 @Configuration @EnableJpaRepositories @Import(RepositoryRestMvcConfiguration.class) @EnableAutoConfiguration(exclude = { BasicErrorController.class }) @EnableMetrics
@Configuration
@EnableJpaRepositories
@Import(RepositoryRestMvcConfiguration.class)
@EnableAutoConfiguration(exclude = { BasicErrorController.class })
@EnableMetrics
public class Application {
public static void main(String[] args) {
ApplicationContext ctx = SpringApplication.run(Application.class, args);
.....................
.....................
和错误控制器如下所示
@Component
@RestController
@RequestMapping(value = "/error")
public class CustomErrorController extends BasicErrorController {
public CustomErrorController(ErrorAttributes errorAttributes) {
super(errorAttributes);
// TODO Auto-generated constructor stub
}
private static final String PATH = "/error";
@RequestMapping(value = PATH)
public String error() {
return "Error handling";
}
@Override
public String getErrorPath() {
return PATH;
}
}
我没有使用这种解决方案,但是,您的请求映射似乎不正确 CustomErrorController的请求映射为'/error',在
@RequestMapping(value = PATH)
public String error() {
return "Error handling";
}
请求映射路径中存在另一个“/error”。然后,此错误处理程序的url为“/error/error”。控制器上有
@RequestMapping(“/error”)
注释,方法上有第二个@RequestMapping(“/error”)
。这将导致/error/error
映射,而不是在getErrorPath()
方法中指定的/error
映射,也可能是在配置中指定的映射(application.properties,server.path.error)