Web应用程序中的Servlet [mvc-dispatcher]抛出了load()异常java.lang.ClassNotFoundException

时间:2015-04-01 06:34:51

标签: java xml hibernate spring-mvc

您好我是Spring的新手,我正在尝试构建一个简单的spring MVC项目 但是当我运行我的代码时,我得到了:Web应用程序中的Servlet [mvc-dispatcher]抛出了load()异常java.lang.ClassNotFoundException

web.xml

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

    <display-name>Sample Spring Maven Project</display-name>

    <servlet>
        <servlet-name>mvc-dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/spring-config.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

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

</web-app>

spring-config.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:context="http://www.springframework.org/schema/context"
     xmlns:util="http://www.springframework.org/schema/util"    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc  http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
     http://www.springframework.org/schema/beans     http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/util    http://www.springframework.org/schema/util/spring-util-3.2.xsd
    http://www.springframework.org/schema/context  http://www.springframework.org/schema/context/spring-context-3.2.xsd">

   <context:component-scan base-package="com.newproject.controller" />
   <context:property-placeholder location="classpath:database.properties" />
   <mvc:annotation-driven />

   <bean id="dataSource"
    class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="${database.driver}" />
    <property name="url" value="${database.url}" />
    <property name="username" value="${database.user}" />
    <property name="password" value="${database.password}" />
    </bean>

    <bean id="sessionFactory"
    class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="annotatedClasses">  
            <list>  
                <value>com.newproject.domain.Employee</value>  
            </list>  
        </property> 
    <property name="hibernateProperties">
     <props>
     <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
     <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
     </props>
     </property>
     </bean>

    <bean id="txManager"
    class="org.springframework.orm.hibernate4.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory" />
    </bean>

    <bean id="persistenceExceptionTranslationPostProcessor"
   class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostPro   cessor" />

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


   <bean id="dataDaoImpl" class="com.newproject.dao.DataDaoImpl" />
    <bean id="dataServiceImpl" class="com.newproject.services.DataServiceImpl"/>
   </beans>

的pom.xml

     <modelVersion>4.0.0</modelVersion>
  <groupId>com.newproject</groupId>
  <artifactId>NewProject</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>
  <name>MyNewProject</name>
  <url>http://maven.apache.org</url>
  <properties>  
  <spring.version>4.0.5.RELEASE</spring.version>  
  <hibernate.version>4.3.5.Final</hibernate.version>  
  <log4j.version>1.2.17</log4j.version>  
  <jdk.version>1.7</jdk.version>  
  <context.path>SpringHibernateAnnotations</context.path>  
 </properties>  
 <developers>  

  <developer>  
   <id>Nagesh Chauhan</id>  
   <email>beingjavaguy@gmail.com</email>  
   <organization>beingjavaguys.com</organization>  
   <organizationUrl>http://www.beingjavaguys.com</organizationUrl>  
   <roles>  
    <role>Java Developer</role>  
   </roles>  
   <timezone>+5:30</timezone>  
  </developer>  
 </developers>  

 <build>  
  <finalName>${pom.artifactId}</finalName>  

  <plugins>  
   <!-- Maven compiler plugin -->  
   <plugin>  
    <artifactId>maven-compiler-plugin</artifactId>  
    <configuration>  
     <source>${jdk.version}</source>  
     <target>${jdk.version}</target>  
    </configuration>  
   </plugin>  
  </plugins>  
 </build>  
 <dependencies>  
  <dependency>  
   <groupId>log4j</groupId>  
   <artifactId>log4j</artifactId>  
   <version>${log4j.version}</version>  
  </dependency>  

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

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

  <dependency>  
   <groupId>org.hibernate</groupId>  
   <artifactId>hibernate-entitymanager</artifactId>  
   <version>${hibernate.version}</version>  
  </dependency>  

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

  <dependency>  
   <groupId>jstl</groupId>  
   <artifactId>jstl</artifactId>  
   <version>1.2</version>  
  </dependency>  
  <dependency>  
   <groupId>mysql</groupId>  
   <artifactId>mysql-connector-java</artifactId>  
   <version>5.1.6</version>  
  </dependency>  


  </dependencies>  
  </project>

1 个答案:

答案 0 :(得分:0)

我最近遇到了同样的错误。我在Eclipse(Luna)中运行了一个Spring MVC项目。我关闭了“自动构建”选项,这就产生了问题。尝试重新打开并尝试再次运行该项目。