Java 禁用特定的ServletContextListener以防止在tomcat上启动
我的项目正在使用Java 禁用特定的ServletContextListener以防止在tomcat上启动,java,spring-boot,tomcat,spring-webflux,servletcontextlistener,Java,Spring Boot,Tomcat,Spring Webflux,Servletcontextlistener,我的项目正在使用springboot和webflux,tomcat 我有一个内部库类,它是ServletContextListener @WebListener public class DevIoServletContextListener implements ServletContextListener { @Inject private DevIoInjector injector; public DevIoServletContextListener() {
springboot
和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);
}
}
禁用
WEB-INF/classes
文件夹中用@WebListener
注释的侦听器的唯一方法是通过WEB-INF/WEB.xml
描述符中的metadata complete
属性禁用注释扫描:
...
这不会禁用ServletContainerInitializers,因此Spring启动初始化将不受影响。是JAR文件还是
WEB-INF/classes
目录中包含DevIoServletContextListener
?servlet容器应该扫描后者的注释,而不是前者。Priotr P.Karwasz是一个JAVA文件。Tkss工作正常!!!