2014-01-22 4 views
1

Привет Я пытаюсь настроить тестовый проект с Maven + пружины 4 + встроенный TOMCATОшибка: Класс не найден AnnotationConfigWebApplicationContext

Я получаю следующее сообщение об ошибке:

INFO: Starting service Tomcat 
Jan 22, 2014 8:27:08 AM org.apache.catalina.core.StandardEngine startInternal 
INFO: Starting Servlet Engine: Apache Tomcat/7.0.47 
Jan 22, 2014 8:27:12 AM org.apache.catalina.core.ApplicationContext log 
INFO: No Spring WebApplicationInitializer types detected on classpath 
Jan 22, 2014 8:27:12 AM org.apache.catalina.core.ApplicationContext log 
INFO: Initializing Spring root WebApplicationContext 
08:27:12.127 [localhost-startStop-1] INFO o.s.web.context.ContextLoader - Root WebApplicationContext: initialization started 
08:27:12.141 [localhost-startStop-1] ERROR o.s.web.context.ContextLoader - Context initialization failed 
org.springframework.context.ApplicationContextException: Failed to load custom context class [         org.springframework.web.context.support.AnnotationConfigWebApplicationContext 
      ]; nested exception is java.lang.ClassNotFoundException:          org.springframework.web.context.support.AnnotationConfigWebApplicationContext 
       
    at org.springframework.web.context.ContextLoader.determineContextClass(ContextLoader.java:399) ~[spring-web-4.0.0.RELEASE.jar:4.0.0.RELEASE] 
    at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:342) ~[spring-web-4.0.0.RELEASE.jar:4.0.0.RELEASE] 
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:280) ~[spring-web-4.0.0.RELEASE.jar:4.0.0.RELEASE] 
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106) [spring-web-4.0.0.RELEASE.jar:4.0.0.RELEASE] 
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4939) [tomcat-embed-core-7.0.47.jar:7.0.47] 
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5434) [tomcat-embed-core-7.0.47.jar:7.0.47] 
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) [tomcat-embed-core-7.0.47.jar:7.0.47] 
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559) [tomcat-embed-core-7.0.47.jar:7.0.47] 
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549) [tomcat-embed-core-7.0.47.jar:7.0.47] 
    at java.util.concurrent.FutureTask.run(FutureTask.java:262) [na:1.7.0_45] 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [na:1.7.0_45] 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [na:1.7.0_45] 
    at java.lang.Thread.run(Thread.java:744) [na:1.7.0_45] 
Caused by: java.lang.ClassNotFoundException:          org.springframework.web.context.support.AnnotationConfigWebApplicationContext 
       
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1702) ~[tomcat-embed-core-7.0.47.jar:7.0.47] 
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1547) ~[tomcat-embed-core-7.0.47.jar:7.0.47] 
    at org.springframework.util.ClassUtils.forName(ClassUtils.java:238) ~[spring-core-4.0.0.RELEASE.jar:4.0.0.RELEASE] 
    at org.springframework.web.context.ContextLoader.determineContextClass(ContextLoader.java:396) ~[spring-web-4.0.0.RELEASE.jar:4.0.0.RELEASE] 
    ... 12 common frames omitted 

Я не уверен, почему, хотя как у меня весна-сеть как часть моего ПОМ

Эй мои POM файлы

родитель POM

<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.ttis.helloworld</groupId> 
<artifactId>helloworld-parent</artifactId> 
<packaging>pom</packaging> 
<version>0.0.1</version> 
<name>helloworld parent project</name> 
<url></url> 


<dependencyManagement> 
    <dependencies> 

     <!-- This makes sure all spring dependencies including transitive are the same version --> 
     <dependency> 
      <groupId>org.springframework</groupId> 
      <artifactId>spring-framework-bom</artifactId> 
      <version>4.0.0.RELEASE</version> 
      <type>pom</type> 
      <scope>import</scope> 
     </dependency> 

     <dependency> 
      <groupId>org.springframework</groupId> 
      <artifactId>spring-orm</artifactId> 
      <version>4.0.0.RELEASE</version> 
     </dependency> 



     <dependency> 
      <groupId>com.ttis.helloworld</groupId> 
      <artifactId>helloworld-entities</artifactId> 
      <version>${project.version}</version> 
     </dependency> 

     <dependency> 
      <groupId>com.ttis.helloworld</groupId> 
      <artifactId>helloworld-common</artifactId> 
      <version>${project.version}</version> 
     </dependency> 

     <dependency> 
      <groupId>com.ttis.helloworld</groupId> 
      <artifactId>helloworld-repositories</artifactId> 
      <version>${project.version}</version> 
     </dependency> 

     <dependency> 
      <groupId>com.ttis.helloworld</groupId> 
      <artifactId>helloworld-services</artifactId> 
      <version>${project.version}</version> 
     </dependency> 
     <dependency> 
      <groupId>junit</groupId> 
      <artifactId>junit</artifactId> 
      <version>4.11</version> 
      <scope>test</scope> 
     </dependency> 
     <dependency> 
      <groupId>ch.qos.logback</groupId> 
      <artifactId>logback-classic</artifactId> 
      <version>1.0.13</version> 
     </dependency> 

     <dependency> 
      <groupId>org.hibernate</groupId> 
      <artifactId>hibernate-entitymanager</artifactId> 
      <version>4.3.0.Final</version> 
     </dependency> 
    </dependencies> 
</dependencyManagement> 


<dependencies> 
    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <scope>test</scope>  
    </dependency> 
    <dependency> 
     <groupId>ch.qos.logback</groupId> 
     <artifactId>logback-classic</artifactId> 
    </dependency> 
    <dependency> 
      <groupId>org.springframework</groupId> 
      <artifactId>spring-orm</artifactId> 
    </dependency> 
    <dependency> 
      <groupId>org.hibernate</groupId> 
      <artifactId>hibernate-entitymanager</artifactId> 
     </dependency> 
</dependencies> 

<modules> 
    <module>helloworld-web</module> 
    <module>helloworld-services</module> 
    <module>helloworld-entities</module> 
    <module>helloworld-common</module> 
    <module>helloworld-repositories</module> 
</modules> 

<properties> 
    <maven.compiler.target>1.7</maven.compiler.target> 
    <maven.compiler.source>1.7</maven.compiler.source> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
</properties></project> 

Мой веб-модуль:

<?xml version="1.0"?> 
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
    <modelVersion>4.0.0</modelVersion> 
    <parent> 
    <groupId>com.ttis.helloworld</groupId> 
    <artifactId>helloworld-parent</artifactId> 
    <version>0.0.1</version> 
    </parent> 

    <artifactId>helloworld-web</artifactId> 
    <packaging>war</packaging> 
    <name>helloworld web app</name> 

    <dependencies> 
     <dependency> 
     <groupId>com.ttis.helloworld</groupId> 
     <artifactId>helloworld-services</artifactId> 
     </dependency> 

     <!-- 
     <dependency> 
     <groupId>com.ttis.helloworld</groupId> 
     <artifactId>helloworld-common</artifactId> 
     </dependency> 
     --> 
     <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-webmvc</artifactId> 
     </dependency> 


    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-orm</artifactId> 
     </dependency> 


    <dependency> 
     <groupId>javax.servlet</groupId> 
     <artifactId>servlet-api</artifactId> 
     <version>2.5</version> 
     <scope>provided</scope> 
    </dependency> 
    </dependencies> 
    <build> 
    <finalName>helloworld</finalName> 


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

       <configuration> 

        <port>9090</port> 

        <path>/helloworld</path> 
       </configuration> 


      </plugin> 
     </plugins> 

    </build> 
</project> 

Мой web.xml

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns=" 
     http://java.sun.com/xml/ns/javaee" 
     xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 
     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_3_0.xsd" 
    id="helloworld" version="3.0"> 

    <display-name>Archetype Created Web Application</display-name> 

     <context-param> 
      <param-name>contextClass</param-name> 
      <param-value> 
         org.springframework.web.context.support.AnnotationConfigWebApplicationContext 
      </param-value> 
   </context-param> 
   <context-param> 
      <param-name>contextConfigLocation</param-name> 
      <param-value>com.ttis.helloworld.config</param-value> 
   </context-param> 
   <listener> 
      <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
   </listener> 
  
   <servlet> 
      <servlet-name>rest</servlet-name> 
      <servlet-class> 
         org.springframework.web.servlet.DispatcherServlet 
      </servlet-class> 
      <init-param> 
         <param-name>contextClass</param-name> 
         <param-value> 
            org.springframework.web.context.support.AnnotationConfigWebApplicationContext 
         </param-value> 
      </init-param> 
      <init-param> 
         <param-name>contextConfigLocation</param-name> 
         <param-value>com.ttis.helloworld.config</param-value> 
      </init-param> 
      <load-on-startup>1</load-on-startup> 
   </servlet> 

</web-app> 

Может кто-нибудь помочь мне понять, что я мог бы быть не хватает?

+0

У вас есть этот класс? * org.springframework.web.context.support.AnnotationConfigWebApplicationContext * – gstackoverflow

+0

http://mavenhub.com/c/org/springframework/web/context/support/annotationconfigwebapplicationcontext/jar – gstackoverflow

ответ

1

К сожалению, он был бело-пространства в файле web.xml

Пример:

<param-value> org.springframework.web.context.support.AnnotationConfigWebApplicationContext </param-value> 

и т.п.

1

Добавить эту зависимость к вашему POM.xml

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

Изменить версию на, которой вы работаете !. повторно запустить mvn clean install Надеюсь, что это помогает

+0

Это работало? Если да, пожалуйста, примите ответ, чтобы сообщить другим, что он решен. – Keerthivasan

0

причину проблемы:

Caused by: java.lang.ClassNotFoundException:   org.springframework.web.context.support.AnnotationConfigWebApplicationContext 

вы можете найти этот класс в том, что коробит:

http://mavenhub.com/c/org/springframework/web/context/support/annotationconfigwebapplicationcontext/jar

если вы используете Maven вы можете добавить себе соответствующие зависимости ,

Следовательно, эта конфигурация невозможна для весны 4

+0

Извините, я не уверен, что следую за вами, почему это невозможно? Не могли бы вы перефразировать свой ответ? Кстати, я сделал добавить следующую зависимость org.springframework весна веб 4.0.0.RELEASE Это не помогло, хотя – at3r

+0

я вижу, что этот класс существует только весной 3 ,вы пытаетесь использовать весну 4 – gstackoverflow

+0

Я предлагаю использовать весну 3.06 версии – gstackoverflow

Смежные вопросы