ContextLoaderListener的问题

时间:2013-01-16 06:54:01

标签: java spring apache-camel

我正在编写一个使用Spring和Apache Camel的教程,但是我遇到了弹簧配置的一些问题。我不断遇到ContextLoaderListener的错误,但我不确定是什么问题。我以前做过简单的Spring应用程序,我相信我已正确布局了web.xml,但我不是一个专家。

如果有人知道修复此错误的方法,那么我实际上可以运行非常有用的项目,我有一份web.xml和下面的错误/堆栈。谢谢!

<?xml version="1.0" encoding="UTF-8"?>

<web-app version="2.4"
     xmlns="http://java.sun.com/xml/ns/j2ee"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
     http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" >

  <display-name>Archetype Created Web Application</display-name>

  <!-- the listener that kick-starts Spring -->
 <listener>
    <listener-class>
      org.springframework.web.context.ContextLoaderListener
    </listener-class>
</listener>

 <!-- location of spring xml files -->
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:camel-config.xml</param-value>
</context-param>

<context-param>
    <param-name>contextConfigLocation1</param-name>
    <param-value>classpath:cxf-config.xml</param-value>
</context-param>

<!-- CXF servlet -->
<servlet>
    <servlet-name>CXFServlet</servlet-name>
    <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<!-- all our webservices are mapped under this URI pattern -->
<servlet-mapping>
    <servlet-name>CXFServlet</servlet-name>
    <url-pattern>/webservices/*</url-pattern>
</servlet-mapping>

Could not instantiate listener org.springframework.web.context.ContextLoaderListender
java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListender
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at org.mortbay.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:392)
    at runjettyrun.ProjectClassLoader.loadClass(ProjectClassLoader.java:89)
    at org.mortbay.jetty.handler.ContextHandler.loadClass(ContextHandler.java:1102)
    at org.mortbay.jetty.webapp.WebXmlConfiguration.initListener(WebXmlConfiguration.java:630)
    at org.mortbay.jetty.webapp.WebXmlConfiguration.initWebXmlElement(WebXmlConfiguration.java:368)
    at org.mortbay.jetty.webapp.WebXmlConfiguration.initialize(WebXmlConfiguration.java:289)
    at org.mortbay.jetty.webapp.WebXmlConfiguration.configure(WebXmlConfiguration.java:222)
    at org.mortbay.jetty.webapp.WebXmlConfiguration.configureWebApp(WebXmlConfiguration.java:180)
    at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1279)
    at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:518)
    at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:499)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
    at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
    at org.mortbay.jetty.Server.doStart(Server.java:224)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
    at runjettyrun.Bootstrap.main(Bootstrap.java:97)
2013-01-16 01:45:03.468:WARN::failed CXFServlet: java.lang.NoClassDefFoundError: org/springframework/web/context/WebApplicationContext
2013-01-16 01:45:03.468:WARN::failed org.mortbay.jetty.webapp.WebAppContext@2aa49512{/camel-example-reportincident,C:\Users\patrick.archambeau\workspace\ApacheCamelTesting\camel-example-reportincident\src\main\webapp}: java.lang.NoClassDefFoundError: org/springframework/web/context/WebApplicationContext
2013-01-16 01:45:03.468:WARN::Error starting handlers
java.lang.NoClassDefFoundError: org/springframework/web/context/WebApplicationContext
    at java.lang.Class.getDeclaredConstructors0(Native Method)
    at java.lang.Class.privateGetDeclaredConstructors(Class.java:2404)
    at java.lang.Class.getConstructor0(Class.java:2714)
    at java.lang.Class.newInstance0(Class.java:343)
    at java.lang.Class.newInstance(Class.java:325)
    at org.mortbay.jetty.servlet.Holder.newInstance(Holder.java:153)
    at org.mortbay.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:428)
    at org.mortbay.jetty.servlet.ServletHolder.doStart(ServletHolder.java:263)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
    at org.mortbay.jetty.servlet.ServletHandler.initialize(ServletHandler.java:736)
    at org.mortbay.jetty.servlet.Context.startContext(Context.java:140)
    at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1282)
    at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:518)
    at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:499)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
    at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
    at org.mortbay.jetty.Server.doStart(Server.java:224)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
    at runjettyrun.Bootstrap.main(Bootstrap.java:97)

2 个答案:

答案 0 :(得分:4)

java.lang.NoClassDefFoundError: org/springframework/web/context/WebApplicationContext告诉您在类路径中缺少WebApplicationContext类。这个类位于spring-web.jar中。因此,要修复此问题,请将spring-web添加到类路径中。

答案 1 :(得分:0)

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

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