Class NotFoundException when loading ContextLoaderListener

I am working on webapp using spring 3.0, hibernate. When I try to deploy my application on WAS 7.0, it gives me an error - Could not load the listener: org.springframework.web.context.ContextLoaderListener]: java.lang.ClassNotFoundException:

This is what my web application looks like:

<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <display-name>ABC</display-name> <welcome-file-list> <welcome-file>index.html</welcome-file> </welcome-file-list> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> 

The exception is the following:

 com.ibm.ws.webcontainer.webapp.WebApp logError SRVE0293E: [Servlet Error]-[Failed to load listener: org.springframework.web.context.ContextLoaderListener]: java.lang.ClassNotFoundException: class java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener at java.beans.Beans.instantiate(Beans.java:190) at java.beans.Beans.instantiate(Beans.java:75) at com.ibm.ws.webcontainer.webapp.WebApp.loadListener(WebApp.java:1643) at com.ibm.ws.webcontainer.webapp.WebAppImpl.loadListener(WebAppImpl.java:671) at com.ibm.ws.webcontainer.webapp.WebApp.loadLifecycleListeners(WebApp.java:1554) 

So, is there something wrong with web.xml?

Edit: Sorry, I didn’t mention, I use Maven to get cans. I have the necessary jar file in the WEB-INF folder, e.g. org.springframework.web.context

+7
source share
9 answers

Take a look at the following link
http://forum.springsource.org/showthread.php?60812-ClassNotFoundException-org.springframework.web.con-text.ContextLoaderListener

It says that you can fix this problem by going to the project properties -> Deploying the assembly and adding an entry about building the Maven Dependency path

+10
source

class java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
on java.beans.Beans.instantiate (Beans.java: 190)

Is the .jar file containing org.springframework.web.context.ContextLoaderListener in the classpath?

+2
source

You have the wrong spring-web dependency definition, not:

 <dependency> <groupId>org.springframework</groupId> <artifactId>org.springframework.web</artifactId> <version>${org.springframework.version}</version> </dependency> 

You should have what I wrote in the comments:

 <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>${spring.version}</version> </dependency> 

ArtifactId - spring-web . ${spring.version} , of course, doesn't matter, just make sure it matches your specific version.

+2
source

Take any jars you add to your project and make sure they are also placed in your WEB-INF / lib directory. Here your server looks at runtime when third-party libraries are referenced. They do not fit there automatically; but there are ways to automate this (e.g. using an ANT script or something like that). In order to slip away and work, you can simply manually copy / paste the jars into this directory. If you add them to this directory outside of your IDE, make sure that you update the folder from your IDE after placing the files there.

+1
source

the java mechanism cannot find the class (as indicated in your exception: java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener )

java will look for the class on the way to the class. you have a folder in the structure of your web application (on the computer where the was'-server is running), where you can put jar files containing classes. you need to put spring.jar or spring -web.jar in this folder. I assume the folder is called lib, and it will probably be located in a folder called WEB-INF, but I'm not sure because I don't know if it was.

after you place the jar file there, you probably need to restart the web server / server application. I hope this helps! ^^

+1
source
 Project> properties> deployment assembly> add > referenced project class path entries> maven dependencies 

Redeployment. It works for me

+1
source

Dave is right! You need all the necessary JARs in two places:

  • If you see exceptions when starting the server, then you do not have the required JAR files in the WEB-INF / lib directory, so you need to leave all the JARs there.

  • If you see any compilation errors in your Java code, then you do not have the correct build path. Store all the JAR files that you embed in WEB-INF / lib in your build path as "Linked Libraries".

0
source

struggled with the same error all day ... I had a spring -web jar, but it turned out that I also needed a spring -context-support bank. I added it to my pom and everything works now.

 <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context-support</artifactId> <version>${org.springframework-version}</version> </dependency> 

error log:

 com.ibm.ws.webcontainer.annotation.WASAnnotationHelper collectClasses unable to instantiate class java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener SRVE0293E: [Servlet Error]-[Failed to load listener: org.springframework.web.context.ContextLoaderListener]: java.lang.ClassNotFoundException: class java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener loadLifecycleListeners SRVE0279E: Error occured while processing global listeners for the application {0}: {1} java.lang.NullPointerException at com.ibm.ws.webcontainer.annotation.WASAnnotationHelper.inject(WASAnnotationHelper.java:266) 
0
source

I had the exact same problem. Hope this helps someone. Some of my dependency jars were not in my WEB-INF / lib folder, but were there in reference libraries. I had to do a clean maven install again to make sure all the banks were loaded in the lib folder. The problem may be in your pom.xml if it is not able to insert jars correctly. So watch out for this.

Project-> Maven clean and build → update the lib folder and make sure that all banks are there (or the specific bank that throws the exception)

0
source

All Articles