java.lang.NoClassDefFoundError: org/springframework/context/ApplicationContext
Asked Answered
P

7

8

I've faced problems for deploying my project which I use jsf/spring/hibernate as a faramework, I added the necessary jars specially org.springframework.web-3.1.0.CI-1162, The error is:

SEVERE: Error configuring application listener of class org.springframework.web.context.ContextLoaderListener
java.lang.NoClassDefFoundError: org/springframework/context/ApplicationContext
    at java.lang.Class.getDeclaredConstructors0(Native Method)
    at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
    at java.lang.Class.getConstructor0(Unknown Source)
    at java.lang.Class.newInstance0(Unknown Source)
    at java.lang.Class.newInstance(Unknown Source)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4150)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4705)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:799)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:779)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:601)
    at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:675)
    at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:601)
    at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:502)
    at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1317)
    at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:324)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1065)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
    at org.apache.catalina.core.StandardService.start(StandardService.java:525)
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)

and the list of jars added:

antlr-2.7.6.jar

commons-dbcb-1.4.jar

commons-collections-3.1.jar

commons-pool.1.6.jar

commons-logging-1.1.jar

dom4j-1.6.1.jar

hibernate3.jar

hibernate-jpa-2.0-api-1.0.1.Final.jar

iText-5.0.4.jar (For Primefaces)

javassist-3.9.0.GA.jar

com.springsource.org.jboss-el-2.0.0.GA.jar (Optional for running on Tomcat 6)

jsf-api.jar (Mojarra 2.0.4)

jsf-impl.jar (Mojarra 2.04)

jta-1.1.jar

log4j-1.2.11.jar

mysql-connector-java-5.0.5.jar (For MySQL)

org.springframework.aop-3.1.0.CI-1162.jar

org.springframework.asm-3.1.0.CI-1162.jar

org.springframework.aspects-3.1.0.CI-1162.jar

org.springframework.beans-3.1.0.CI-1162.jar

org.springframework.context-3.1.0.CI-1162.jar

org.springframework.context.support-3.1.0.CI-1162.jar

org.springframework.core-3.1.0.CI-1162.jar

org.springframework.expression-3.1.0.CI-1162.jar

org.springframework.jdbc-3.1.0.CI-1162.jar

org.springframework.orm-3.1.0.CI-1162.jar

org.springframework.oxm-3.1.0.M1.jar

org.springframework.transaction-3.1.0.CI-1162.jar

org.springframework.web-3.1.0.CI-1162.jar

org.springframework.web.portlet-3.1.0.M1.jar

org.springframework.web.servlet-3.1.0.CI-1162.jar

poi-3.2-FINAL-20081019.jar (For Primefaces)

primefaces-3.5jar

slf4j-api-1.6.1.jar

slf4j-jdk14-1.6.1.jar

qlfj4-log4j12-1.6.4.jar

Presentative answered 13/4, 2013 at 15:19 Comment(2)
How are you building the war file? (Maven? Ant? Eclipse?)Monumental
If you found the correct answer here, please mark it as correct so that it might help future visitors with similar issues. Thank youOctagonal
O
24

For this error, there can be different solutions. I have noted down the ones that had worked for me.

Solution 1. This is always happened in deployment and debugging environment. In deployment environment, just make sure your server classpath has included the Spring jar library (e.g spring-4.0.4.jar).

In debugging environment, the steps may vary from different IDE, but the solution is same. In Eclipse, developers usually will create a tomcat, jboss…whatever application server for debugging, just make sure the correct Spring jars are included.

  1. Double click on your debugging server
  2. Click on the “Open launch configuration” to access the server environment
  3. Click on the classpath tab
  4. Include the Spring jar file here , it may also required common log jar due to Spring dependency.
  5. Done, run your application again.

.

Solution 2. If you are using Maven as a build tool and downloading dependencies using it, there can be some jar conflict. Because Tomcat servers normally provide some jars such as servlet-api and jpa-api. So if you again included them using maven; there will be problems in identifying them.

Solution 3. If you are using Eclipse as your IDE and using Maven as your build tool and tomcat as your server; remember Tomcat server will not look on the jars which are just inside the folders. For that there's a small trick,

  1. Right click on your project and select properties
  2. From the displayed window, select Deployment Assembly
  3. Select Add
  4. Add Maven dependencies
  5. Click Apply and Click OK

Hope one of these solutions would help you to solve your problem. Happy Coding and make sure that is using Java.

Octagonal answered 16/9, 2014 at 9:59 Comment(0)
D
1

In my situation, I use maven to build the project, just because the war file is not created correctly, it will leads to this exception. I check the war file and run install again, that solve my problem.

Dusky answered 2/4, 2015 at 3:21 Comment(0)
D
0

You have to download necessary jar file. You can download spring-context.jar file from the following link

http://mvnrepository.com/artifact/org.springframework/spring-context/3.2.2.RELEASE

Deathblow answered 13/4, 2013 at 15:35 Comment(16)
spring-context is already in the list (org.springframework.context-3.1.0.CI-1162.jar)Monumental
You cannot know without trying this jar file. Also i updated my answerDeathblow
As you can see ApplicationContext class in this jar file.Deathblow
um, you really think it's a good idea to just replace this one jar with the 3.2.2.RELEASE version, and none of the other spring jars?? The OP has a seriously misconfigured setupMonumental
the class ApplicationContext is in the jar ! that's why I can't find a solution, any proposition, any help??Presentative
@arbtristol you are right about spring configuration is hard. However, it is not necessary to change all jar files. When used this jar, there will be no problem.Deathblow
@Presentative what is your problem except this class not found exception because it is solvedDeathblow
so I have to replace all jars files?Presentative
no isn't solved, how can I do, I have to replace all jar file?Presentative
No @hela, why dont you try by adding this jar file to your project then run the projectDeathblow
@mucayufa this jar org.springframework.context-3.1.0.CI-1162.jar is already in the project !!Presentative
Please just replace org.springframework.context-3.1.0.CI-1162.jar file with my suggested jar fileDeathblow
so I've done what you said then tomcat is now blocked with this error: 13-Apr-2013 17:42:36 org.apache.catalina.core.StandardServer await WARNING: StandardServer.await: Invalid command 'GET / HTTP/1.1' received and the file can not be opened, any idea? and this error still : SEVERE: Error configuring application listener of class org.springframework.web.context.ContextLoaderListener java.lang.NoClassDefFoundError: org/springframework/context/ApplicationContextPresentative
The same error has happend. Firstly delete out or target folder then recreate war fileDeathblow
sorry but I don't understand what I've to do? what you mean by the war file?Presentative
As i understand from added jar files your project is web project. Therefore, when you run the project a war file is created in out folder or target folder. When you delete this folder you will also delete created warDeathblow
M
0

I suggest you replace all the Spring jars with the most up to date version (3.2.2.RELEASE)

Monumental answered 13/4, 2013 at 16:46 Comment(2)
I've tried before with other version of spring but it's the same problem !!Presentative
Updating the version of the spring jars is what CAUSED this problem for me.Poultryman
H
0

Make sure your server classpath has included the Spring jar library. Watch this link.

Heliolatry answered 30/3, 2014 at 16:11 Comment(0)
S
0

I use eclipse and find that there is no maven dependencies config on Deployment Assembly, so I modified .classpath from

     <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
       <attributes>
            <attribute name="maven.pomderived" value="true"/>
       </attributes>
     </classpathentry>

to

     <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
       <attributes>
            <attribute name="maven.pomderived" value="true"/>
            <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
       </attributes>
     </classpathentry>
Sanders answered 24/12, 2018 at 6:9 Comment(0)
M
0

In my case, I had duplicate dependencies in my pom.xml. Try checking and remove the duplicates

Mirna answered 11/10, 2023 at 10:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.