9

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

Here is how my web app looks:

<?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 being thrown is as follows,

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 anything wrong in web.xml ?

Edit: Sorry I did not mention, I am using Maven to get the jars. I have the required jar file in the WEB-INF folder too i.e. org.springframework.web.context

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Ritesh Mengji
  • 6,000
  • 9
  • 30
  • 46
  • related issues http://stackoverflow.com/questions/10046654/maven-spring-dynamic-web-module-eclipse-java-lang-classnotfoundexcepti/12600686#12600686 – Adriano Sep 26 '12 at 11:49

9 Answers9

11

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

It says you can fix this problem by going to project properties -> Deployment Assembly and adding the Maven Dependency Build Path entry

2

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

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

matt b
  • 138,234
  • 66
  • 282
  • 345
  • Sorry I did not mention, I am using Maven to load all the jar files, and I see org.sptingframework.web in the pom file but not org.springframework.web.context.ContextLoaderListener. Will this effect? – Ritesh Mengji May 18 '11 at 16:53
  • 1
    That would be spring-web-3.0.xx.jar. – abalogh May 18 '11 at 16:54
  • In Maven dialect: org.springframework spring-web ${spring.version} – abalogh May 18 '11 at 16:56
  • I already have this in my Maven org.springframework org.springframework.web ${org.springframework.version} – Ritesh Mengji May 18 '11 at 17:01
  • and how do you deploy the application to the server? Are you copying a .war built by Maven? – matt b May 18 '11 at 17:19
  • and does RAD copy the Maven dependencies? do you have spring-web-$version.jar in WEB-INF/lib? – matt b May 18 '11 at 17:58
  • And RAD (whatever that might be) copies everything else, just not this jar? Or you have an empty WEB-INF/lib in your exploded war directory? If you copy files manually, the application starts all right? – abalogh May 19 '11 at 14:11
  • I see that the folder WEB-INF/lib is empty...Hmm, looks like the jar files are not copied in it. Other than the lib everything else looks fine.. – Ritesh Mengji May 19 '11 at 21:01
2

You have the wrong definition of the spring-web dependency, instead of:

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

You should have what I've written in the comments:

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

ArtifactId is spring-web. ${spring.version} of course is not important, just be sure it matches your defined version string.

abalogh
  • 8,239
  • 2
  • 34
  • 49
1
Project> properties> deployment assembly> add > referenced project class path entries> maven dependencies 

Deploy again. It works for me

Vipin CP
  • 3,642
  • 3
  • 33
  • 55
1

Take any jars that you add to your project and make sure that they're also placed in your WEB-INF/lib directory. This is where your server looks at runtime when 3rd party libs are referenced. They aren't put there automatically; but there are ways you can automate this (ie using an ANT script or something like that). Just to get things up and running though, you can just manually copy/paste jars to that directory. If you add them to that directory outside of your IDE, make sure you refresh the folder from within your IDE after placing the files there.

Dave
  • 6,141
  • 2
  • 38
  • 65
1

the java engine fails too find the class (as your exception says: java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener)

java will search for the class on the class-path. you have a folder in your web app structure (on the computer where your 'was'-server runs) where you can put jar-files containing classes. you need to put spring.jar or spring-web.jar in this folder. i'm guessing the folder is called lib, and it will probably be located in a folder called WEB-INF, but i'm not sure, cause i don't know 'was'.

after you've put the jar-file in there, you'll probably need to restart your web/app-server. hope this helps! ^^

davogotland
  • 2,718
  • 1
  • 15
  • 19
0

struggled with this same error all day ... i had the spring-web jar, but turns out that i also needed the spring-context-support jar. i added it into my pom and everything is working 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)
matt1616
  • 433
  • 4
  • 8
0

I had the same exact problem. Hopefully this helps someone. Some of my dependency jars were missing from my WEB-INF/lib folder but were there in Referenced libraries. I had to to do a maven clean install again to make sure all the jars were pulled into the lib folder. The problem might be in your pom.xml too if it is not able to pull in the jars properly. So keep an eye out for that as well.

Project-> Maven clean and build -> lib folder refresh and make sure all jars are there (or the particular jar that throws the exception)

Guru
  • 1,653
  • 1
  • 7
  • 14
0

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

  1. If you are seeing exceptions when you start the server, then you do not have the required JARs in WEB-INF/lib dir, so you need to keep all the JARs there.

  2. If you are seeing any compile errors in your Java code, then you do not have your build path configured correctly. Keep all the JARs you put in WEB-INF/lib in your build path as "Referenced Libraries".

m2p
  • 81
  • 3