如何在AbstractAnnotationConfigDispatcherServletInitializer中使用DelegatingFilterProxy

时间:2015-01-09 20:47:54

标签: spring spring-mvc spring-java-config

我想在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?

0 个答案:

没有答案