我有两个模块的项目:1)中间层和 2)webapp。
我的中间层有 bean 配置文件,它对指定的包进行组件扫描以加载 bean。我创建的此类类之一是 ApplicationContextUtils,它扩展了 JAR SPRING-CONTEXT 中的 ApplicationContextAware 接口。(是的,我已经用注释 @Component 标记了类 ApplicationContextUtils)。该项目的 pom 已将 spring-context-3.2.4.RELEASE 声明为依赖 jar,我可以在 maven 依赖项中看到它。我通过运行一个加载所有 bean 的测试单独测试了这个类,它运行良好。
现在,转到 webapp,webapp 的 pom 将中间层描述为它的依赖项。我可以看到这个中间层项目在 webapps 中被列为 maven 依赖项。将此项目从 Eclipse 部署到 Tomcat 我收到以下错误:
org.springframework.beans.factory.CannotLoadBeanClassException: Error loading class [com.jms.testjms.ApplicationContextUtils] for bean with name 'applicationContextUtils' defined in file [F:\Projects\ActiveMQ\JMSProject\target\classes\com\jms\testjms\ApplicationContextUtils.class]: problem with class file or dependent class; nested exception is java.lang.NoClassDefFoundError: org/springframework/context/ApplicationContextAware
.
.
.
Caused by: java.lang.NoClassDefFoundError: org/springframework/context/ApplicationContextAware
(& lot of error chains ..)
我能得到的唯一理由是 jar spring-context 不在类路径中。但是,当我检查 WEB-INF/lib 时,当然有 jar spring-context-3.2.4.RELEASE 是接口 ApplicationContextAware 的来源。我不确定为什么spring找不到这个接口。
我正在使用弹簧 3.2.4。我的 web.xml 在启动期间使用 ContextLoaderListener 加载资源。该项目是使用 maven 构建的。
任何见解将不胜感激。
来自中间层的 POM:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.jms.test</groupId>
<artifactId>JmsTest</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<name>Spring Utility</name>
<url>http://www.springframework.org</url>
<description>
<![CDATA[
This project is a minimal jar utility with Spring configuration.
]]>
</description>
<properties>
<maven.test.failure.ignore>true</maven.test.failure.ignore>
<spring.framework.version>3.2.4.RELEASE</spring.framework.version>
</properties> <dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.framework.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.framework.version}</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jms</artifactId>
<version>${spring.framework.version}</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-core</artifactId>
<version>5.7.0</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-spring</artifactId>
<version>5.8.0</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-pool</artifactId>
<version>5.8.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</build>
来自 webapp 的 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>JmsProtoWebApp</groupId>
<artifactId>JMSWebApp</artifactId>
<packaging>war</packaging>
<version>1.0.0-SNAPSHOT</version>
<name>JMSWebApp Maven Webapp</name>
<url>http://maven.apache.org</url>
<properties>
<maven.test.failure.ignore>true</maven.test.failure.ignore>
<spring.framework.version>3.2.4.RELEASE</spring.framework.version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.framework.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.framework.version}</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jms</artifactId>
<version>${spring.framework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.framework.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>servlet-api</artifactId>
<version>6.0.37</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.jms.test</groupId>
<artifactId>JmsTest</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
<build>
<finalName>JMSWebApp</finalName>
</build>
</project>
项目结构和部署组装:http: //imgur.com/zydcqSm