我有兩個模塊的項目:1)Midtier & 2)webapp。Tomcat上下文初始化失敗
我的mid-tier有一個bean配置文件,它執行組件掃描指定的包來加載bean。我創建的這樣的類之一是ApplicationContextUtils,它擴展了JAR包中的ApplicationContextAware接口SPRING-CONTEXT。 (是的,我用註解@Component標記了類ApplicationContextUtils)。這個項目的pom聲明瞭spring-context-3.2.4.RELEASE作爲依賴jar &我可以在maven依賴中看到它。我通過運行一個測試來測試這個類,它加載了所有運行良好的豆類&。
現在,移到webapp上,webapp的pom將midtier描述爲它的依賴。我可以看到這個中間層項目被列爲webapps中的maven依賴項。從部署月食這個項目到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 ..)
的唯一理由,我可以得到的是罐子彈簧上下文不會在類路徑。但是,當我檢查WEB-INF/lib時,當然有jar spring-context-3.2.4.RELEASE這是接口ApplicationContextAware的源代碼。我不知道爲什麼春天找不到這個界面。
我正在使用彈簧3.2.4。我的web.xml在啓動時使用ContextLoaderListener來加載資源。該項目使用maven構建。
任何見解將不勝感激。從中層
POM:從web應用
<?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>
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
請在eclipse中發佈您的'pom'並可能包含您的項目結構的圖像。 –
我已經使用pom從mid-tier和webapp更新了這篇文章。包括項目結構和部署程序集 –
的鏈接,您還需要將您的彈簧罐部署到tomcat。 – happymeal