Javadoc 说AnnotationMethodHandlerExceptionResolver、ResponseStatusExceptionResolver和DefaultHandlerExceptionResolver在 DispatcherServlet 中默认启用。
我正在尝试创建一个HandlerExceptionResolverComposite
,但我想检索HandlerExceptionResolver
默认启用的实例。我试过了@Autowired
,但没有成功。
我目前的解决方案是:
@Configuration
public class ErrorHandling {
// @Autowired
// AnnotationMethodHandlerExceptionResolver amher;
//
// @Autowired
// ResponseStatusExceptionResolver rser;
//
// @Autowired
// DefaultHandlerExceptionResolver dher;
@Bean
HandlerExceptionResolverComposite getHandlerExceptionResolverComposite() {
HandlerExceptionResolverComposite result
= new HandlerExceptionResolverComposite();
List<HandlerExceptionResolver> l
= new ArrayList<HandlerExceptionResolver>();
l.add(new AnnotationMethodHandlerExceptionResolver());
l.add(new ResponseStatusExceptionResolver());
l.add(new DefaultHandlerExceptionResolver());
result.setExceptionResolvers(l);
return result;
}
}
我的问题是:如何检索HandlerExceptionResolver
默认启用的实例?如果我创建自己的实例会不会有问题?