java.lang.ClassNotFoundException:eclipse中的org.springframework.web.context.ContextLoaderListener [英] java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener in eclipse

查看:213
本文介绍了java.lang.ClassNotFoundException:eclipse中的org.springframework.web.context.ContextLoaderListener的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个简单的Spring MVC应用程序(不使用maven),这将在浏览器上打印你的世界。它是eclipse中的一个动态项目,因此我将所有必需的jar文件放在两个构建路径以及 WEB-INF / lib 文件夹中



我尝试了两个解决方案,两者都没有起作用。



我发现的解决方案:


  1. 清理tomcat工作目录

  2. 将spring-mvc / spring-web.jar jar文件放在lib

这是我的 web.xml

 <?xml version =1.0encoding =UTF-8?> 
< web-app>

< display-name> Spring MVC应用程序< / display-name>

< servlet>
< servlet-name> mvc-dispatcher< / servlet-name>
< servlet-class> org.springframework.web.servlet.DispatcherServlet< / servlet-class>
< load-on-startup> 1< / load-on-startup>
< / servlet>

< servlet-mapping>
< servlet-name> mvc-dispatcher< / servlet-name>
< url-pattern> /< / url-pattern>
< / servlet-mapping>

< context-param>
< param-name> contextConfigLocation< / param-name>
< param-value> /WEB-INF/mvc-dispatcher-servlet.xml< / param-value>
< / context-param>

< listener>
< listener-class> org.springframework.web.context.ContextLoaderListener< / listener-class>
< / listener>

< / web-app>

并且在配置contextLoaderListener时没有输入错误,那么有什么问题吗?解决方案

  2014年1月20日8:16:39 PM org.apache.catalina.core.StandardService startInternal 
INFO :启动服务Catalina
2014年1月20日8:16:39 PM org.apache.catalina.core.StandardEngine startInternal
INFO:启动Servlet引擎:Apache Tomcat / 7.0.11
一月20 ,2014 8:16:40 PM org.apache.catalina.core.StandardContext listenerStart
SEVERE:配置org.springframework.web.context.ContextLoaderListener类的应用程序侦听器错误
java.lang.ClassNotFoundException:org .springframework.web.context.ContextLoaderListener
在org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1676)
在org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader。 java:1521)
在org.apache.catalina.core.DefaultInstanceManager.loadClass(Defa ultInstanceManager.java:415)
在org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:397)
在org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java: 118)
在org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4618)
在org.apache.catalina.core.StandardContext $ 1.call(StandardContext.java:5184)
在org.apache.catalina.core.StandardContext $ 1.call(StandardContext.java:5179)
在java.util.concurrent.FutureTask $ Sync.innerRun(未知源)
在java。 util.concurrent.FutureTask.run(未知来源)
在java.util.concurrent.ThreadPoolExecutor.runWorker(未知来源)
在java.util.concurrent.ThreadPoolExecutor $ Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

2014年1月20日8:16:40 PM org.apache.catalina.core.StandardContext listenerStart
SEVERE:Skipped安装应用程序由于以前的错误导致的stener
2014年1月20日8:16:40 PM org.apache.catalina.core.StandardContext startInternal
SEVERE:错误listenerStart
2014年1月20日8: 16:40 PM org.apache.catalina.core.StandardContext startInternal
SEVERE:Context [/ SpringSample]由于以前的错误而启动失败
2014年1月20日8:16:40 PM org.apache.coyote .AbstractProtocolHandler start
INFO:启动ProtocolHandler [http-bio-8081]
2014年1月20日8:16:40 PM org.apache.coyote.AbstractProtocolHandler start
INFO:启动ProtocolHandler [ajp-bio-8009]
2014年1月20日8:16:40 PM org.apache.catalina.startup.Catalina start
INFO:服务器启动在4010 ms

最终我收到404错误,因为我的服务无法加载

解决方案

我在Eclipse中有同样的问题。当我做一个maven干净的安装,并将生成的WAR文件移动到我的Tomcat webapp文件夹,它将运行没有问题。但是,为了调试,我想在Eclipse中运行,但会抛出以下错误。

 严重:配置应用程序侦听器错误类org.springframework.web.context.ContextLoaderListener 

我googled,直到我发现以下博客文章。



http:// commonexceptions。 blogspot.com/2014/01/java.html



正如作者所说:


当我没有将maven依赖项添加到
的构建路径时,导致此异常。我正在使用eclipse与maven,所以不得不在构建路径中包含
maven依赖关系,如下所述。


查看该解决方案的职位。它是一个简单的eclipse部署程序集配置修复程序。让我约30秒,现在我可以在Eclipse中调试我的Spring webapp。



以下是相关步骤:



在项目Web部署程序集中添加Maven依赖项:




  • 打开项目属性(示例:在项目浏览器中右键单击
    项目名称选择属性)。

  • 选择部署程序集。

  • 点击右侧导航栏上的添加...按钮。

  • 从指令类型菜单中选择Java构建路径条目,然后单击下一步。

  • 从Java构建路径中选择Maven Dependencies条目菜单

  • 点击完成。

  • 现在,应该将Maven依赖关系添加到Web部署程序集中,并应运行。






  • 如果Tomcat运行停止它

  • 打开服务器视图:窗口,然后选择显示视图,然后选择其他>服务器>服务器

  • 右键单击Tomcat服务器,然后选择清除Tomcat工作目录。

  • 右键单击Tomcat服务器,然后选择清除

  • 重新启动Tomcat服务器



上述解决方案应该可以解决异常。


I am doing a simple Spring MVC application(not using maven) which will print hello world on browser. It is a dynamic project in eclipse, so I put all the required jar files IN both build path as well as in WEB-INF/lib folder

I tried two solutions and both didn't work.

Solutions I found:

  1. cleaning tomcat work directory
  2. putting spring-mvc/spring-web.jar jar file in lib

Here is my web.xml

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

    <display-name>Spring MVC Application</display-name>

    <servlet>
        <servlet-name>mvc-dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>mvc-dispatcher</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/mvc-dispatcher-servlet.xml</param-value>
    </context-param>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

</web-app>

and there is no typo mistake in configuring the contextLoaderListener, then what is the problem, is there any other solution

Jan 20, 2014 8:16:39 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Jan 20, 2014 8:16:39 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.11
Jan 20, 2014 8:16:40 PM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Error configuring application listener of class org.springframework.web.context.ContextLoaderListener
java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1676)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1521)
    at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:415)
    at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:397)
    at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:118)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4618)
    at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5184)
    at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5179)
    at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

Jan 20, 2014 8:16:40 PM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Skipped installing application listeners due to previous error(s)
Jan 20, 2014 8:16:40 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Error listenerStart
Jan 20, 2014 8:16:40 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Context [/SpringSample] startup failed due to previous errors
Jan 20, 2014 8:16:40 PM org.apache.coyote.AbstractProtocolHandler start
INFO: Starting ProtocolHandler ["http-bio-8081"]
Jan 20, 2014 8:16:40 PM org.apache.coyote.AbstractProtocolHandler start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Jan 20, 2014 8:16:40 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 4010 ms

eventually I am getting 404 error as my service is failed to loaded

解决方案

I had this same problem in Eclipse. When I would do a maven clean install and move the generated WAR file to my Tomcat webapp folder it would run with no problems. However, inorder to debug I wanted to run in Eclipse but it would throw the following error.

SEVERE: Error configuring application listener of class   org.springframework.web.context.ContextLoaderListener

I googled around until I found the following blog post.

http://commonexceptions.blogspot.com/2014/01/java.html

As the author explains:

This exception was caused when i did not add the maven dependencies to the build path. I was using eclipse with maven, so had to include the maven dependencies in the build path as explained below.

See the post for the solution. It is a simple eclipse Deployment Assembly configuration fix. Took me about 30 seconds and now I can debug my Spring webapp in Eclipse.

Here are the relevant steps from the post:

Adding Maven dependencies in project web deployment assembly :

  • Open project properties(example: In project explorer rightClick on project name to select "Properties").
  • Select "Deployment Assembly".
  • Click "Add..." button on the right navigation.
  • Select "Java Build Path Entries" from menu of Directive Type and then click "Next".
  • Select "Maven Dependencies" from Java Build Path Entries menu
  • click "Finish".
  • Now the "Maven Dependencies" should be added to the Web Deployment Assembly and it should run.

When using Eclipse WDT and using unmodified and previously working project :

  • If Tomcat is running Stop it
  • Open the "Servers" view: Window then select "Show view" and then select "Other" > Server > Servers
  • Right Click on the Tomcat Server and then select "Clean Tomcat Work Directory".
  • Right Click on the Tomcat Server and then select "Clean"
  • Restart the Tomcat Server

The above solution should resolve the exception.

这篇关于java.lang.ClassNotFoundException:eclipse中的org.springframework.web.context.ContextLoaderListener的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆