dre*_*nda 10 spring web.xml listener spring-boot
我正在尝试将我的项目转换为Spring Boot项目(嵌入Jetty的可执行jar文件).所有工作都使用标准示例,但我希望将旧的web.xml迁移到Spring Boot.
我迁移了Servlet和过滤器,但我不明白如何迁移过滤器:
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
    <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<listener>
    <listener-class>org.granite.config.GraniteConfigListener</listener-class> 
</listener> 
    <listener>
    <listener-class>org.granite.gravity.websocket.GravityWebSocketDeployer</listener-class>
</listener>
我创建了@SpringBootApplication类,并在所有配置中编写:
@Bean
@Order(1)
public FilterRegistrationBean springSecurityFilterChain() {     
    FilterRegistrationBean filterRegBean = new FilterRegistrationBean();
    DelegatingFilterProxy delegatingFilterProxy = new DelegatingFilterProxy();
    filterRegBean.setFilter(delegatingFilterProxy);
    List<String> urlPatterns = new ArrayList<String>();
    urlPatterns.add("/*");
    filterRegBean.setUrlPatterns(urlPatterns);
    return filterRegBean;
}
有人可以解释我应该如何转换听众?
Spring Boot将@Beans使用servlet容器自动注册以下任何类型:
例如,要注册GravityWebSocketDeployer哪个是向配置类ServletContextListener添加@Bean方法:
@Bean
public GravityWebSocketDeployer gravityWebSocketDeployer() {
    return new GravityWebSocketDeployer();
}
对于 RequestContext 阅读此内容
 @Bean
    @ConditionalOnMissingBean(RequestContextListener.class)
    public RequestContextListener requestContextListener() {
        return new RequestContextListener();
    }
对于另一个侦听器,当您使用 spring-boot 时会自动注册,如此链接所示。
为了你自己的听众。
public class MyAdditionListeners extends SpringBootServletInitializer {
    protected final Log logger = LogFactory.getLog(getClass());
    @Override
    public void onStartup(ServletContext servletContext) throws ServletException {
        WebApplicationContext rootAppContext = createRootApplicationContext(servletContext);
        if (rootAppContext != null) {
            servletContext.addListener(new YourListenerHere());
        }
        else {
            this.logger.debug("No ContextLoaderListener registered, as "
                    + "createRootApplicationContext() did not "
                    + "return an application context");
        }
    }
最后有一个链接,您可以在其中找到有关侦听器和 SpringApplication 类的一些信息。阅读部分
| 归档时间: | 
 | 
| 查看次数: | 19860 次 | 
| 最近记录: |