Springboot -> Springboot 2: 2 Spring WebApplicationInitializers detected on classpath

蓝咒 提交于 2019-12-11 06:47:48

问题


I've got a web app I recently upgraded from springboot to springboot 2. When I deploy it to Tomcat 8 it seems to start but doesn't start fully.

In localhost.2019-09-04.log (Tomcat) I have the following error:

2 Spring WebApplicationInitializers detected on classpath

I've tried various things from this post:

2 Spring WebApplicationInitializers detected on classpath

but has no luck. How can I find out which package another WebApplicationInitializers might be in?


回答1:


That log is output from SpringServletContainerInitializer which is Servlet 3.0 ServletContainerInitializer that handles WebApplicationInitializer.

So the most simple way to find out what are these WebApplicationInitializer is to create our own ServletContainerInitializer that also handle WebApplicationInitializer and print their information to console.

@HandlesTypes(WebApplicationInitializer.class)
public class FooServletContainerInitializer implements ServletContainerInitializer {

    @Override
    public void onStartup(Set<Class<?>> c, ServletContext ctx) throws ServletException {
        for (Class<?> clazz : c) {
            System.out.println(clazz);
            System.out.println(clazz.getResource('/' + clazz.getName().replace('.', '/') + ".class"));
            System.out.println("----------------");
        }

    }
}

I am referring to this for how to print the JAR file path of a class.

To register it , create a file META-INF/services/javax.servlet.ServletContainerInitializer. Inside this file , include the fully qualified class name of our ServletContainerInitializer :

org.foo.bar.FooServletContainerInitializer

Then it should execute during Tomcat starts.



来源:https://stackoverflow.com/questions/57791571/springboot-springboot-2-2-spring-webapplicationinitializers-detected-on-clas

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!