错误在春季4 | 抛出java.lang.ClassNotFoundException:org.

2019-10-20 09:47发布

我收到以下错误而执行弹簧4的应用程序,你能帮帮我吗?

抛出java.lang.ClassNotFoundException:org.springframework.web.servlet.DispatcherServlet在org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1324)在org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java :1177)在org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:550)在org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:531)在org.apache.catalina.core。 DefaultInstanceManager.newInstance(DefaultInstanceManager.java:150)在org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1105)在org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1041)在组织.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4932)在org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5218)在org.apache.catalina.util.LifecycleBase.start(LifecycleBase的.java:150)在org.apache.catalina.core.ContainerBase $ StartChild.call(ContainerBase.java:1396)在org.apache.catalina.core.ContainerBase $ StartChild.call(ContainerBase.java:1386)在java.util.concurrent.FutureTask.run(来源不明)在java.util中。 concurrent.ThreadPoolExecutor.runWorker(来源不明)在java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(来源不明)在java.lang.Thread.run(来源不明)

这里是我pom.xml

<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>com.anandc.webmvc</groupId>
    <artifactId>MVC_Test</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <name>Spring4MVCWebApp</name>
    <url>http://maven.apache.org</url>
    <properties>
        <spring.version>4.0.5.RELEASE</spring.version>
        <freemarker.version>2.3.20</freemarker.version>
        <spring.security.version>3.2.3.RELEASE</spring.security.version>
        <spring.security.taglib.version>3.0.5.RELEASE</spring.security.taglib.version>
        <spring.jdbc.version>4.0.2.RELEASE</spring.jdbc.version>
        <common.logging.version>1.1.1</common.logging.version>
        <servlet.api.version>3.0.1</servlet.api.version>
        <jstl.version>1.2</jstl.version>        
    </properties>

    <dependencies>

        <!-- JUnit dependencies Start -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
        <!-- JUnit dependencies End -->

        <!-- FTL dependencies Start -->
        <dependency>
            <groupId>org.freemarker</groupId>
            <artifactId>freemarker</artifactId>
            <version>${freemarker.version}</version>
        </dependency>
        <!-- FTL dependencies End -->

        <!-- Spring dependencies Start -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${spring.version}</version>
        </dependency>

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

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

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context-support</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <!-- Spring dependencies End -->
        <!-- Spring Security Artifacts - START -->
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-web</artifactId>
            <version>${spring.security.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-config</artifactId>
            <version>${spring.security.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-taglibs</artifactId>
            <version>${spring.security.taglib.version}</version>
        </dependency>
        <!-- Spring Security Artifacts - END -->

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>${jstl.version}</version>
            <scope>compile</scope>
        </dependency>       
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>${servlet.api.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>${common.logging.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>${spring.jdbc.version}</version>
        </dependency>

    </dependencies>

    <build>
        <sourceDirectory>src</sourceDirectory>
        <finalName>Spring4MVCWebApp</finalName>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <warSourceDirectory>WebContent</warSourceDirectory>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

这是我的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>Freemarker_SpringMVC_example</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>

  <servlet>
        <servlet-name>spring</servlet-name>
        <servlet-class>
            org.springframework.web.servlet.DispatcherServlet
        </servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>spring</servlet-name>
        <url-pattern>*.html</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">

    <!-- freemarker config -->
    <bean id="freemarkerConfig" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
      <property name="templateLoaderPath" value="/WEB-INF/ftl/"/>
    </bean>

    <!--
      View resolvers can also be configured with ResourceBundles or XML files. If you need
      different view resolving based on Locale, you have to use the resource bundle resolver.
    -->
    <bean id="viewResolver" class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
      <property name="cache" value="true"/>
      <property name="prefix" value=""/>
      <property name="suffix" value=".ftl"/>
    </bean>

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

</beans>

另外,请建议,如果我需要在我的POM任何清理工作时,我使用Spring 4。

先感谢您 !

请注意 - 我已经通过现有的类似的问题了,但是没有这些帮助。

问候,
阿南德查万

Answer 1:

你可以尝试:
1,改变弹簧servlet.xml中:

FROM    

<bean id="viewResolver" class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
  <property name="cache" value="true"/>
  <property name="prefix" value=""/>
  <property name="suffix" value=".ftl"/>
</bean>

TO <property name="prefix" value="/"/>

2,如果你把你的罐子上的图书馆 ,你尽量把那些罐子WEB-INF / lib目录

我通过上述方法的手段解决这个问题。
但我真的不知道为什么。



Answer 2:

尝试下面的伎俩,它每次都为我工作:

  1. 选择项目并转到属性>部署大会
  2. 点击添加
  3. 选择Java Build Path项
  4. 如果存在任何Maven依赖,选择所有(按Ctrl + A),然后单击Finish
  5. 清洗和刷新你的项目

发布并尝试立即启动服务器,

希望这会帮助,最好的问候,



文章来源: Error in Spring 4 | java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet