Search code examples
springintellij-ideaglassfishclassnotfoundexception

ContextLoaderListener not found


I'm starting to learn Spring framework and almost from start faced with an issue: as I'm developing in IntellijIDEA, i didn't found it easy to configure spring mvc project. Having been deployed to Glassfish, the project constantly gives me an error

java.io.IOException: com.sun.enterprise.admin.remote.RemoteFailureException: Error occurred during deployment: Exception while loading the app : java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: java.lang.IllegalArgumentException: java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener. Please see server.log for more details. 

Also, watching Glassfish log all I see is:

org.apache.catalina.LifecycleException: java.lang.IllegalArgumentException: javax.servlet.ServletException: java.lang.NoClassDefFoundError: org/springframework/core/io/Resource

and a bunch of similar thrown exceptions.

Here is my context-param configuration made in web.xml

<context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/config/spring/applicationContext.xml</param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

What can be done with this? Here's the github project: https://github.com/vaano94/Project


Solution

  • This should have nothing to do with your dependencies resolution at compile time since you can compile your project and the configuration seems quite fine in your project descriptor.

    However, as you are receiving a set of ClassNotFoundException , that means that the application server is not able to find some classes at runtime, those basically related to Spring, so you have to review your project artifact dependencies.

    Within Intellij IDEA:

    • Open the project configuration view: File -> Project Structure
    • Navigate to your project web artifact: Project Settings -> Artifacts then click on your project exploded war artifact.
    • In the Output Layout tab, navigate to the libraries folder, i.e. /WEB-INF/lib/ and check that all the Spring needed artifacts are included. In case any one is missing, which should be the case for the core, web and mvc dependencies I guess.