gpt4 book ai didi

java - 错误: Class not found AnnotationConfigWebApplicationContext

转载 作者:行者123 更新时间:2023-11-30 04:03:46 24 4
gpt4 key购买 nike

嗨,我正在尝试使用 maven + spring 4 + 嵌入式 tomcat 设置一个测试项目

我收到以下错误:

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

我不知道为什么,因为我有 spring-web 作为我的 pom 的一部分

嘿,这是我的 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>

谁能帮我弄清楚我可能缺少什么?

最佳答案

将此依赖项添加到您的 POM.xml

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

将版本更改为您工作的版本!重新运行mvn clean install希望这有帮助

关于java - 错误: Class not found AnnotationConfigWebApplicationContext,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21283475/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com