开发者

ClassNotFoundException while loading ContextLoaderListener

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


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


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?


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.


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.


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! ^^


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

Deploy again. It works for me


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".


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)


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)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜