错误org.springframework.web.servlet.DispatcherServlet - 上下文初始化失败

时间:2016-02-26 10:53:07

标签: java spring maven spring-mvc servlets

我已经在项目中正确映射了每个bean,因此提供了相应的路径。该项目在创建它的机器上运行良好。但是当其他开发人员导入项目并成功完成清洁后安装,尝试运行它,它会抛出异常。另外,我看过一些类似的标题问题,但没有一个对我有用。

注意:DAO图层或数据库图层是作为单独的项目创建的,并作为jar包含在项目中。

例外:

2016-02-26 15:09:33,709 [localhost-startStop-1] INFO  org.springframework.beans.factory.support.DefaultListableBeanFactory - Overriding bean definition for bean 'artistController' with a different definition: replacing [Generic bean: class [com.ceelive.controller.ArtistController]; scope=singleton; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in file [D:\ceelive-workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\ceelive\WEB-INF\classes\com\ceelive\controller\ArtistController.class]] with [Generic bean: class [com.ceelive.controller.ArtistController]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in ServletContext resource [/WEB-INF/servlet/ceeliveservlet/servlet-context.xml]]
2016-02-26 15:09:33,921 [localhost-startStop-1] WARN  org.springframework.web.context.support.XmlWebApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'artistController' defined in ServletContext resource [/WEB-INF/servlet/ceeliveservlet/servlet-context.xml]: Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: com/ceelive/dao/manager/artist/ArtistDao
2016-02-26 15:09:33,921 [localhost-startStop-1] ERROR org.springframework.web.servlet.DispatcherServlet - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'artistController' defined in ServletContext resource [/WEB-INF/servlet/ceeliveservlet/servlet-context.xml]: Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: com/ceelive/dao/manager/artist/ArtistDao
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
 at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
 at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
 at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
 at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)
 at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839)
 at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)
 at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:668)
 at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:634)
 at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:682)
 at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:553)
 at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:494)
 at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
 at javax.servlet.GenericServlet.init(GenericServlet.java:158)
 at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1238)
 at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1151)
 at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1038)
 at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4997)
 at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5289)
 at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
 at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408)
 at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398)
 at java.util.concurrent.FutureTask.run(FutureTask.java:266)
 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
 at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NoClassDefFoundError: com/ceelive/dao/manager/artist/ArtistDao
 at java.lang.Class.getDeclaredMethods0(Native Method)
 at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
 at java.lang.Class.getDeclaredMethods(Class.java:1975)
 at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:609)
 at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:521)
 at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:507)
 at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:241)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineConstructorsFromBeanPostProcessors(AbstractAutowireCapableBeanFactory.java:1069)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1042)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
 at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
 at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
 at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
 at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:351)
 at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1481)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1226)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanF...

的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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.cimple</groupId>
  <artifactId>ceelive</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>ceelive Maven Webapp</name>
  <url>http://maven.apache.org</url>
  <dependencies>

        <!-- Spring Dependencies-->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>4.2.4.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>4.2.4.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>4.2.4.RELEASE</version>
            <exclusions>
                <exclusion>
                    <groupId>commons-logging</groupId>
                    <artifactId>commons-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <!-- Need this for json to/from object -->
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.1.0</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
            <version>2.1.0</version>
        </dependency>

        <!-- jstl Servlet -->
        <dependency>
          <groupId>javax.servlet</groupId>
          <artifactId>jstl</artifactId>
          <version>1.2</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet.jsp.jstl</groupId>
            <artifactId>jstl-api</artifactId>
            <version>1.2</version>
            <scope>provided</scope>
        </dependency>

        <!-- Logging -->
        <!-- <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>jcl-over-slf4j</artifactId>
            <version>1.7.14</version>
        </dependency>

        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>1.1.3</version>
        </dependency> -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.14</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>jcl-over-slf4j</artifactId>
            <version>1.7.14</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.7.14</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.16</version>
            <scope>runtime</scope>
        </dependency>
        <!-- Apache tiles -->
        <dependency>
           <groupId>org.apache.tiles</groupId>
           <artifactId>tiles-api</artifactId>
           <version>2.2.2</version>
        </dependency>
        <dependency>
           <groupId>org.apache.tiles</groupId>
           <artifactId>tiles-core</artifactId>
           <version>2.2.2</version>
               <!-- <exclusions>
                    <exclusion>
                      <groupId>org.slf4j</groupId>
                      <artifactId>slf4j-jdk14</artifactId>
                    </exclusion>
               </exclusions> -->
        </dependency>
        <dependency>
           <groupId>org.apache.tiles</groupId>
           <artifactId>tiles-jsp</artifactId>
           <version>2.2.2</version>
        </dependency>
        <dependency>
           <groupId>org.apache.tiles</groupId>
           <artifactId>tiles-servlet</artifactId>
           <version>2.2.2</version>
        </dependency>
        <dependency>
           <groupId>org.apache.tiles</groupId>
           <artifactId>tiles-template</artifactId>
           <version>2.2.2</version>
        </dependency>

        <!-- compile only, runtime container will provide this -->
        <!-- Need this for config annotation -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
            <scope>provided</scope>
        </dependency>

    <!-- ceeliveDAO - Custom dependency -->
    <dependency>
         <groupId>com.cimple</groupId>
         <artifactId>ceeliveDAO</artifactId>
         <version>0.0.1-SNAPSHOT</version>
    </dependency>
  </dependencies>

  <build>
    <finalName>ceelive</finalName>

          <pluginManagement>
        <plugins>

            <!-- <plugin>
              <groupId>org.apache.tomcat.maven</groupId>
              <artifactId>tomcat6-maven-plugin</artifactId>
              <version>2.2</version>
            </plugin> -->
            <plugin>
              <groupId>org.apache.tomcat.maven</groupId>
              <artifactId>tomcat7-maven-plugin</artifactId>
              <version>2.2</version>
            </plugin>

            <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-compiler-plugin</artifactId>
              <version>3.3</version>
              <configuration>
                <source>1.8</source>
                <target>1.8</target> 
              </configuration>
            </plugin>

            <plugin>
                <groupId>org.eclipse.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <version>9.2.11.v20150529</version>
                <configuration>
                    <scanIntervalSeconds>10</scanIntervalSeconds>
                    <webApp>
                        <contextPath>/spring4ajax</contextPath>
                    </webApp>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-eclipse-plugin</artifactId>
                <version>2.10</version>
                <configuration>
                    <downloadSources>true</downloadSources>
                    <downloadJavadocs>true</downloadJavadocs>
                    <wtpversion>2.0</wtpversion>
                    <wtpContextName>spring4ajax</wtpContextName>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>


            <plugin>
                <groupId>it.session.maven.plugins</groupId>
                <artifactId>tiles-maven-plugin</artifactId>
                <version>${maventiles.plugin.version}</version>
                <extensions>true</extensions>
            </plugin>
         </plugins>
      </pluginManagement>
  </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" 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>service</display-name>

    <!-- Deafult pages -->
    <welcome-file-list>
       <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>

    <!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/servlet/root-context.xml</param-value>
    </context-param>

    <!-- Creates the Spring Container shared by all Servlets and Filters -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <!-- Log listner -->
    <listener>
        <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
    </listener>

    <!-- Processes application requests -->
    <servlet>
        <servlet-name>ceelive</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/servlet/ceeliveservlet/servlet-context.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <!-- Servlet Mapping -->
   <servlet-mapping>
      <servlet-name>ceelive</servlet-name>
      <url-pattern>/</url-pattern>
   </servlet-mapping>
</web-app>

servlet的context.xml中

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


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

    <!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->

    <!-- Enables the Spring MVC @Controller programming model -->
    <annotation-driven />

    <!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
    <resources mapping="/resources/**" location="/resources/" />

    <!-- Event Dao Bean -->
    <beans:bean id="eventDao" class="com.ceelive.dao.manager.event.EventDaoImpl">
    </beans:bean>
    <!-- Artist Dao Bean -->
    <beans:bean id="artistDao" class="com.ceelive.dao.manager.artist.ArtistDaoImpl">
    </beans:bean>
    <!-- Event Service Bean -->
    <beans:bean id="eventService" class="com.ceelive.service.event.EventServiceImpl">
        <beans:property name="eventDao" ref="eventDao"></beans:property>
    </beans:bean>
    <!-- Artist Service Bean -->
    <beans:bean id="artistService" class="com.ceelive.service.artist.ArtistServiceImpl">
        <beans:property name="artistDao" ref="artistDao"></beans:property>
    </beans:bean>
    <!-- Event Controller Bean -->
    <beans:bean id="eventController" class="com.ceelive.controller.EventController">
        <beans:property name="eventService" ref="eventService"></beans:property>
        <beans:property name="beanUtil" ref="beanUtil"></beans:property>
    </beans:bean>
    <!-- Artist Controller Bean -->
    <beans:bean id="artistController" class="com.ceelive.controller.ArtistController">
        <beans:property name="artistService" ref="artistService"></beans:property>
        <beans:property name="beanUtil" ref="beanUtil"></beans:property>
    </beans:bean>
    <!-- BeanUtil bean -->
    <beans:bean id="beanUtil" class="com.ceelive.utility.BeanUtil">
    <!-- HibernateConfiguration bean -->
    </beans:bean>
       <beans:bean id="hibernateConfiguration" class="com.ceelive.configuration.HibernateConfiguration">
    </beans:bean>
    <!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
        <beans:bean id="tilesConfigurer"
        class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
        <beans:property name="definitions">
            <beans:list>
                <beans:value>/WEB-INF/tiles.xml</beans:value>
            </beans:list>
        </beans:property>
    </beans:bean>
    <beans:bean id="tilesViewResolver"
        class="org.springframework.web.servlet.view.UrlBasedViewResolver">
        <beans:property name="viewClass">
            <beans:value>
                org.springframework.web.servlet.view.tiles2.TilesView
            </beans:value>
        </beans:property>
        <beans:property name="order" value="0"/>
    </beans:bean>

    <context:component-scan base-package="com.frameworkonly.tilesapp" />
</beans:beans>

2 个答案:

答案 0 :(得分:1)

我在eclipse中将Tomcat Server添加到Java Build Path中解决了同样的错误。

右键点击该项目 - &gt;构建路径 - &gt;配置构建路径 - &gt;添加库..(显示在对话框的右侧) - &gt;服务器运行时 - &gt;选择&#34; Apache Tomcat v ..&#34; - &GT;完成

然后在服务器上运行项目。

答案 1 :(得分:0)

我认为你因版本冲突而得到异常。请检查java和tomcat服务器的版本。