No Spring WebApplicationInitializer types detected on classpath

前端 未结 13 1803
野的像风
野的像风 2020-11-29 08:03

My Eclipse project is suddenly no longer deploying properly. I can\'t trace it to any particular change I\'ve made to the environment.

I have tested with multiple s

相关标签:
13条回答
  • 2020-11-29 08:43

    Watch out if you are using Maven. Your folder's structure must be right.

    When using Maven, the WEB-INF directory must be inside webapp:

    src/main/webapp/WEB-INF
    
    0 讨论(0)
  • 2020-11-29 08:48

    In my case it also turned into a multi-hour debugging session. Trying to set up a more verbose logging turned out to be completely futile because the problem was that my application did not even start. Here's my context.xml:

    <?xml version='1.0' encoding='utf-8'?>
    <Context path="/rc2" docBase="rc2" antiResourceLocking="false" >
        <JarScanner>
            <JarScanFilter
                tldScan="spring-webmvc*.jar, spring-security-taglibs*.jar, jakarta.servlet.jsp.jstl*.jar"
                tldSkip="*.jar"
                <!-- my-own-app*.jar on the following line was missing! -->
                pluggabilityScan="${tomcat.util.scan.StandardJarScanFilter.jarsToScan}, my-own-app*.jar"
                pluggabilitySkip="*.jar"/>
        </JarScanner>
    </Context>
    

    The problem was that to speed up the application startup, I started skipping scanning of many JARs, unfortunately including my own application.

    0 讨论(0)
  • 2020-11-29 08:49

    I spent hours on this, and the solution was:

    • Stop Tomcat
    • "Project" menu -> Clean -> Clean all projects
    • Servers tab -> Tomcat -> Right click -> Clean...
    • Right click on project -> Run as -> Run on server
    0 讨论(0)
  • 2020-11-29 08:49

    WebApplicationInitializer is an interface you can implement in one of your classes. At startup Spring is scanning for this classes, as long as you are using servlet spec 3 and have a metadata-complete="false" attribute in your web.xml. But that doesn't seem to be the problem. The only error I can figure out is the missing slf4j-log4j12.jar.

    0 讨论(0)
  • 2020-11-29 08:50

    xml was not in the WEB-INF folder, thats why i was getting this error, make sure that web.xml and xxx-servlet.xml is inside WEB_INF folder and not in the webapp folder .

    0 讨论(0)
  • 2020-11-29 08:55

    I spent my whole day today investigating this problem and none of the answers helped. Here is my scenario. The WebApplicationInitializer types in my case are inside jar files. we have a multi-module gradle web project where each module is packaged as a jar and included in the web artifact. The problem is that Apache tomcat's classloader is not looking for the implementations of WebApplicationIntializer in WEB-INF/lib instead its looking for those types directly under WEB-INF/classes folder.

    Here is what I ended up doing for anyone who faces this problem in future.

    I implemented a ServletContainerInitializer myself and added that class name to META-INF/services/javax.servlet.ServletContainerInitializer

    In the implementation, I copied the code from SpringServletContainerIntializer and used reflections to find the classes implementing a CustomWebApplicationInitializer interface, I did not make use of spring's WebApplicationInitializer interface to avoid any conflicts. Basically I have the same contract as WebApplicationInitializer with a different name. Now on startup, my container initializer is called and I delegated the call to all my CustomWebApplicationInitializers.

    Based on my search I also found that the loader used for tomcat can be updated to have it search in WEB-INF/lib but I have little control over the tomcat I deploy my app to so went with the above solution. Hope this helps someone.

    0 讨论(0)
提交回复
热议问题