我正在开发Rest Spring启动应用程序,我的代码为:
@SpringBootApplication public class Initializer扩展了SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Initializer.class);
}
}
具有CRUD方法的接口
@ControllerAdvice
的异常处理程序类,其中包含@ExceptionHandler(NotImplementedException.class){ //message }
我有一些资源跟我说a
,b
,c
,d
。
截至目前,我仅实施了a
和b
,因此,如果客户端尝试访问NotImplementedException
和c
,我想抛出自定义d
。
我想知道我应该在哪里抛出此异常,是否必须使用ResourceHandlers
之类的内容,如果是,如何使用它以及需要哪些配置?
答案 0 :(得分:0)
1-控制器建议类必须extends ResponseEntityExceptionHandler
2-覆盖处理异常的原始方法。对于您的情况:
public handleHttpRequestMethodNotSupported (HttpRequestMethodNotSupportedException ex, HttpHeaders headers, HttpStatus status, WebRequest request)
3-在您用来覆盖处理程序的方法中做您想做的事情。
仅此而已。