java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet 错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23765821/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 01:06:38  来源:igfitidea点击:

java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet error

javaeclipsespringspring-mvcivy

提问by Aniket Thakur

Not sure why am I getting this error. Lots of similar questions here but none have worked for me till now.

不知道为什么我会收到这个错误。这里有很多类似的问题,但到目前为止没有一个对我有用。

My ivy file is

我的常春藤文件是

<ivy-module version="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd">
    <info
        organisation=""
        module="knoxWeb"
        status="integration">
    </info>

    <dependencies>
        <dependency org="org.springframework" name="spring-core" rev="4.0.3.RELEASE"/>
        <dependency org="org.springframework" name="spring-context" rev="4.0.3.RELEASE"/>
        <dependency org="org.springframework" name="spring-web" rev="4.0.3.RELEASE"/>
        <dependency org="org.springframework" name="spring-webmvc" rev="4.0.3.RELEASE"/>
        <dependency org="org.springframework" name="spring-beans" rev="4.0.3.RELEASE"/>
    </dependencies>
</ivy-module>

and my web.xml is

我的 web.xml 是

<?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_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>Knox Web Interface</display-name>

    <servlet>
    <servlet-name>action</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
   </servlet>
    <servlet-mapping>
        <servlet-name>action</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>
</web-app>

I have resolved ivy. Still getting the error. Also i can see the Class in my eclipse.

我已经解决了常春藤。仍然收到错误。我也可以在我的日食中看到班级。

enter image description here

在此处输入图片说明

I am really stuck at this. Any help or suggestion is appreciated.

我真的被困在这个问题上。任何帮助或建议表示赞赏。

PS : I also tried adding < dependency org="org.springframework" name="spring" rev="2.5.6"/>but ivy does not resolve. I get

PS:我也尝试添加< dependency org="org.springframework" name="spring" rev="2.5.6"/>但常春藤无法解决。我得到

Some projects fail to be resolved
Impossible to resolve dependencies of #TestWebProject;working@BLT430LT3201C
download failed: com.oracle.toplink#toplink;10.1.3!toplink.jar
unresolved dependency: com.oracle#oc4j;1.0: not found
unresolved dependency: com.oracle#toplink-essentials;2.41: not found
unresolved dependency: javax.ejb#ejb;3.0: not found
download failed: com.bea.wlplatform#commonj-twm;1.1!commonj-twm.jar
unresolved dependency: jexcelapi#jxl;2.6.6: not found
download failed: javax.jms#jms;1.1!jms.jar
download failed: javax.faces#jsf-api;1.1!jsf-api.jar
download failed: javax.resource#connector;1.0!connector.jar

Not sure if this has anything to do with above problem. I am searching http://mvnrepository.com/artifact/org.springframeworkfor all dependency info.

不确定这是否与上述问题有关。我正在http://mvnrepository.com/artifact/org.springframework搜索所有依赖信息。

My project structure is

我的项目结构是

enter image description here

在此处输入图片说明

WEB-INF/lib directory is empty.

WEB-INF/lib 目录为空。

Source : http://opensourceforgeeks.blogspot.in/2014/05/javalangclassnotfoundexception.html

来源:http: //opensourceforgeeks.blogspot.in/2014/05/javalangclassnotfoundexception.html

采纳答案by Aniket Thakur

Thanks a lot guys for your valuable comments. You are all right. Jar files must be in WEB-INF/lib. Or you can tell Eclipse that it can find the jars in additional location and not just WEB-INF/lib.

非常感谢小伙伴们的宝贵意见。你没事。Jar 文件必须在WEB-INF/lib. 或者您可以告诉 Eclipse 它可以在其他位置找到 jar,而不仅仅是WEB-INF/lib.

How do we do that?

我们怎么做?

  • Right click the project and select properties. Now go to Deployment Assembly.
  • 右键单击项目并选择属性。现在转到部署程序集。

enter image description here

在此处输入图片说明

  • Now select Add and select Java build path entries.
  • 现在选择添加并选择 Java 构建路径条目。

enter image description here

在此处输入图片说明

  • Ivy option is automatically populated. Select that.
  • 常春藤选项会自动填充。选择那个。

enter image description here

在此处输入图片说明

  • And you are done.Select Apply and ok. Classnotfound Exception vanishes.
  • 大功告成。选择应用,然后确定。Classnotfound 异常消失。

enter image description here

在此处输入图片说明