未找到org.springframework.web.servlet.DispatcherServlet

时间:2016-11-26 00:33:10

标签: java spring servlets

好吧,这一直困扰着我,我已经环顾四周,其他所有线程都说要去部署程序集。问题是,当我去那里时,没有相关的依赖'点击。

喜欢这个帖子:      org.springframework.web.servlet.DispatcherServlet not found with VMWare vFabric tc Server and maven dispatcherservlet-not-found-with-vmware-vfabric

我进入该屏幕并且没有maven依赖点可以点击。

我的web.xml是:

<web-app id="WebApp_ID" 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>Spring MVC Application</display-name>

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

<servlet-mapping>
  <servlet-name>SpringMVC</servlet-name>
  <url-pattern>/</url-pattern>
</servlet-mapping>

</web-app>

和-servlet.xml

   xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
 http://www.springframework.org/schema/beans     
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context 
http://www.springframework.org/schema/context/spring-context-3.0.xsd">

<context:component-scan base-package="com.tutorialspoint" />

<bean     class="org.springframework.web.servlet.view.InternalResourceViewResolver">
  <property name="prefix" value="/WEB-INF/jsp/" />
  <property name="suffix" value=".jsp" />
</bean>

</beans>

感谢任何帮助。我正在使用STS工具/ Eclipse。

p p继承人。所有的jar都在java resources / libraries / maven dependecies文件夹中

     <project xmlns="http://maven.apache.org/POM/4.0.0"      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0     http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>SpringMVC</groupId>
 <artifactId>SpringMVC</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>
  <name>SpringMVC</name>

<properties>
    <java.version>1.8</java.version>
</properties>

    <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.4.2.RELEASE</version>
</parent>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
        </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
    </dependency>
    <dependency>
        <groupId>com.jayway.jsonpath</groupId>
        <artifactId>json-path</artifactId>
        <version>2.2.0</version>
    </dependency>
    <dependency>
     <groupId>org.json</groupId>
  <artifactId>json</artifactId>
  <version>20090211</version>
   </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>2.8.5</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <version>1.3.2.RELEASE</version>
        <scope>test</scope>
    </dependency>
  </dependencies>

 <build>
<sourceDirectory>src</sourceDirectory>
<resources>
  <resource>
    <directory>src</directory>
    <excludes>
      <exclude>**/*.java</exclude>
    </excludes>
  </resource>
</resources>
<plugins>
  <plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.5.1</version>
    <configuration>
      <source>1.8</source>
      <target>1.8</target>
    </configuration>
    </plugin>
    <plugin>
    <artifactId>maven-war-plugin</artifactId>
    <version>3.0.0</version>
    </plugin>
   </plugins>
  </build>
</project>

例外是:

ava.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1892)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1735)
at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:504)
at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:486)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:113)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1133)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1072)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5368)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5660)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1571)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1561)
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)

编辑:我得到它编译但现在得到

警告:在DispatcherServlet中找不到带有URI [/ HelloWeb /]的HTTP请求的映射,名称为&#39; HelloWeb

3 个答案:

答案 0 :(得分:0)

试试这个;
使用 Servlet API 2.5 并更改您的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"
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">
<servlet>
    <servlet-name>spring</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring-servlet.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>spring</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>

spring-servlet.xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<beans
   xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:p="http://www.springframework.org/schema/p"
   xmlns:context="http://www.springframework.org/schema/context"
   xsi:schemaLocation="http://www.springframework.org/schema/beans
                    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                    http://www.springframework.org/schema/context
                    http://www.springframework.org/schema/context/spring-context-3.0.xsd ">

    <context:component-scan base-package="com.tutorialspoint"></context:component-scan>

    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"><!-- Here, the InternalResourceViewResolver class is used for the ViewResolver. -->
        <property name="prefix" value="/WEB-INF/jsp/"></property><!-- prefix can be any thing -->
        <property name="suffix" value=".jsp"></property>
    </bean>

修改 您必须在spring 3.x中包含maven依赖项,如下所示

<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-context</artifactId>
  <version>3.1.0.RELEASE</version>
</dependency>
<dependency>
 <groupId>org.springframework</groupId>
 <artifactId>spring-webmvc</artifactId>
 <version>3.1.0.RELEASE</version>
</dependency>

根据您在评论中的查询;在这种情况下,Spring不会创建默认构造函数,因此最好转到setter注入或创建默认构造函数。

答案 1 :(得分:0)

您可以尝试在pom.xml文件中添加这些依赖项,这依赖于我遗忘的内容。

 IWebDriver driver = new FirefoxDriver();
    static void Main(string[] args)
    {
    }

    [Test]
    public void VerifyTitle()
    {
        //Write Actual Test
        string title = driver.Title;
        // Assert.AreEqual(title, "DoneThedeal");
        ////I wanted to keep it simple change it back if u wish
        if (title.Contains("DoneTheDeal"))
        {
            Console.WriteLine(title);
        }
        else
        {
            Console.WriteLine("Title not found");
        }

    }
    [SetUp]
    public void Setup()
    {
        //start browser and oprn url

        driver.Navigate().GoToUrl("http://Donethedeal.com/");
    }

    [TearDown]
    public void CleanupTest()
    {
        //close browser
        driver.Quit();
    }
}

答案 2 :(得分:0)

完全希望这是最好的答案:

我遇到问题我下载了日食Noen.3和Dirctly创建Maven项目。服务器无法启动时出现相同的问题:找不到DispatcherServlet类错误:

  1. 我创建了简单的动态Web项目并将项目转换为Maven项目
  2. 步骤:右键单击项目configure-&gt;转换为maven项目

    详情请参阅下面的链接 http://javawebtutor.com/articles/spring/spring-mvc-hibernate-crud-example.php