我想在AbstractAnnotationConfigDispatcherServletInitializer的onStartup方法中注册DelegatingFilterProxy。不幸的是,servlet初始化时尚未创建DelegatingFilterProxy的委托bean:
@Order(1)
public class MvcWebApplicationInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
...
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
super.onStartup(servletContext);
FilterRegistration.Dynamic localeFilter = servletContext.addFilter("localeFilter", new DelegatingFilterProxy("localeFilter"));
localeFilter.addMappingForUrlPatterns(null, false, "/*");
}
...
}
@Configuration
@EnableWebMvc
public class WebConfig extends WebMvcConfigurerAdapter {
...
@Bean
public LocaleFilter localeFilter() {
return new LocaleFilter();
}
...
}
如何确保在servlet的启动之前创建localeFilter bean?