3

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?

Paul Grenyer
  • 1,713
  • 3
  • 30
  • 51

2 Answers2

3

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.

Ken Chan
  • 84,777
  • 26
  • 143
  • 172
  • seem that it does not load .If the WAR is packaged correctly , after it is deployed to Tomcat , you can find that the file `javax.servlet.ServletContainerInitializer` is exploded to the path `$TomcatHomeDir/webapps/your-app-name/WEB-INF/classes/META-INF/services` ? – Ken Chan Sep 06 '19 at 17:53
  • I think we found it another way: org.springframework.boot.autoconfigure.jersey.JerseyAutoConfiguration$JerseyWebApplicationInitializer@39cfe31b Class Name: org.springframework.boot.autoconfigure.jersey.JerseyAutoConfiguration$JerseyWebApplicationInitializer 09-Sep-2019 14:29:30.331 INFO [localhost-startStop-1] org.apache.catalina.core.ApplicationContext.log Initializer details: ToString: uk.org.wlma.drs.DrsServletInitializer@6bb5804b Class Name: uk.org.wlma.drs.DrsServletInitializer – Paul Grenyer Sep 09 '19 at 14:12
0

I had this problem and after doing a new basic spring boot with the bare minimum I still had this problem. The last thing left was to check the innocent application.properties and found with trial and error that there was an invalid property. Once this line was removed, everything worked.

This was the property:

logging.level.org.apache.catalina=DEBUG