禁用特定的servletcontextlistener以防止在tomcat上启动

bzzcjhmw  于 2021-10-10  发布在  Java
关注(0)|答案(1)|浏览(235)

我的项目正在使用 spring boot 具有 webflux , tomcat .
我有一个内部库类,它是 ServletContextListener ```
@WebListener
public class DevIoServletContextListener implements ServletContextListener {
@Inject
private DevIoInjector injector;

public DevIoServletContextListener() {
}

public void contextInitialized(ServletContextEvent event) {
    this.injector.inject();
}

public void contextDestroyed(ServletContextEvent event) {
}

}

此内部类在方法内部引发异常 `contextInitialized` :

[ERROR ] SRVE0283E: Exception caught while initializing context: java.lang.NullPointerException
at br.com.dev.lib.DevIoServletContextListener.contextInitialized(DevIoServletContextListener.java:33)

这门课对我的发展不重要。。我想忽略或禁用此侦听器,是否可能?
我不会在这个侦听器中进行更改,因为它是一个库中的内部类。
我将感谢任何帮助。
我尝试添加@servletcomponentscan(“br.com.dev.bit.io”),我的包只在主类中,但不起作用。

@SpringBootApplication
@EnableAutoConfiguration
@ComponentScan("br.com.dev.bit.io")
@ServletComponentScan("br.com.dev.bit.io")
public class Application extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}

nuypyhwy

nuypyhwy1#

禁用带注解的侦听器的唯一方法 @WebListenerWEB-INF/classes 文件夹将完全禁用通过 metadata-complete 中的属性 WEB-INF/web.xml 描述符:

<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
    metadata-complete="true"
    version="4.0">
    ...
</web-app>

这不会禁用 ServletContainerInitializer s、 因此,spring引导初始化将不受影响。

相关问题