加载ContextLoaderListener时出现ClassNotFoundException

时间:2011-05-18 16:42:24

标签: java spring maven

我正在开发一个使用spring 3.0,hibernate的webapp。当我尝试在WAS 7.0上部署我的应用程序时,它会给我错误 - 无法加载侦听器:org.springframework.web.context.ContextLoaderListener]:java.lang.ClassNotFoundException:

以下是我的网络应用的外观:

<?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>

抛出的异常如下,

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)

那么,web.xml中有什么问题吗?

编辑:对不起,我没有提及,我正在使用Maven来获取罐子。我在WEB-INF文件夹中也有所需的jar文件,即org.springframework.web.context

9 个答案:

答案 0 :(得分:11)

看看以下链接
http://forum.springsource.org/showthread.php?60812-ClassNotFoundException-org.springframework.web.con-text.ContextLoaderListener

它说您可以通过转到项目属性来解决此问题 - &gt;部署程序集并添加Maven依赖关系构建路径条目

答案 1 :(得分:2)

  

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

类路径中包含org.springframework.web.context.ContextLoaderListener的.jar文件是什么?

答案 2 :(得分:2)

您对spring-web依赖项的定义错误,而不是:

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

你应该在评论中写下我所写的内容:

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

ArtifactId是spring-web${spring.version}当然不重要,只要确保它与您定义的版本字符串匹配。

答案 3 :(得分:1)

将您添加到项目中的任何罐子放入并确保它们也放在WEB-INF / lib目录中。这是您的服务器在引用第三方库时查看运行时的位置。它们不会自动放在那里;但有一些方法可以自动化(即使用ANT脚本或类似的东西)。只是为了完成并运行,您只需手动将jar复制/粘贴到该目录即可。如果将它们添加到IDE外部的目录中,请确保在将文件放在IDE中后从IDE中刷新文件夹。

答案 4 :(得分:1)

java引擎失败也找到了这个类(例如你的例外:java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener

java将在类路径上搜索类。您的Web应用程序结构中有一个文件夹(在运行'''服务器的计算机上),您可以在其中放置包含类的jar文件。你需要将spring.jar或spring-web.jar放在这个文件夹中。我猜这个文件夹名为lib,它可能位于一个名为WEB-INF的文件夹中,但我不确定,因为我不知道'是'。

将jar文件放入其中后,您可能需要重新启动web / app-server。希望这可以帮助! ^^

答案 5 :(得分:1)

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

再次部署。 它对我有用

答案 6 :(得分:0)

戴夫是对的!您需要在两个地方拥有所有必需的JAR:

  1. 如果您在启动服务器时看到异常,那么您在WEB-INF / lib目录中没有所需的JAR,因此您需要将所有JAR保留在那里。

  2. 如果您在Java代码中看到任何编译错误,那么您没有正确配置构建路径。将您放置在构建路径中的WEB-INF / lib中的所有JAR保存为“Referenced Libraries”。

答案 7 :(得分:0)

整天都在努力解决这个错误...... 我有弹簧网罐,但事实证明我还需要弹簧环境支持罐。 我把它添加到我的pom中,现在一切正常。

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

错误日志:

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)

答案 8 :(得分:0)

我遇到了同样的问题。 希望这有助于某人。 我的WEB-INF / lib文件夹中缺少一些依赖项jar,但是在Referenced库中有。 我不得不再次进行maven clean安装,以确保所有的jar都被拉入lib文件夹。 问题可能在你的pom.xml中,如果它无法正确拉入罐子。因此,请密切注意这一点。

项目 - &GT; Maven清理和构建 - &gt; lib文件夹刷新并确保所有jar都存在(或抛出异常的特定jar)

相关问题