문제

I have a project involving spring-mvc/jms/active-mq. Getting the following exception when trying to deploy to Tomcat 7.26 within Eclipse Juno:

Caused by: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.jms.connection.CachingConnectionFactory] for bean with name 'cachingConnectionFactory' defined in ServletContext resource [/WEB-INF/authmgr-servlet.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.jms.connection.CachingConnectionFactory
Caused by: java.lang.ClassNotFoundException: org.springframework.jms.connection.CachingConnectionFactory

pom.xml

<project>   
<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <org.springframework.version>3.2.3.RELEASE</org.springframework.version>
    <org.springframework.security.version>3.1.3.RELEASE</org.springframework.security.version>
    <hibernate.version>4.1.9.Final</hibernate.version>
    <org.apache.tiles.version>2.2.2</org.apache.tiles.version>
</properties>
<repositories>
    <repository>
        <id>repository.springsource.release</id>
        <name>SpringSource Repository</name>
        <url>http://repo.springsource.org/release</url>
    </repository>
    <repository>
        <id>repository.jboss.org-public</id>
        <name>JBoss.org Maven repository</name>
        <url>https://repository.jboss.org/nexus/content/groups/public</url>
    </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId>org.springframework.integration</groupId>
        <artifactId>spring-integration-mail</artifactId>
        <version>2.2.1.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-orm</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-oxm</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-test</artifactId>
        <version>${org.springframework.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-jms</artifactId>
        <version>${org.springframework.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>javax.jms</groupId>
        <artifactId>jms</artifactId>
        <version>1.1</version>
    </dependency>
    <dependency>
        <groupId>org.apache.activemq</groupId>
        <artifactId>activemq-all</artifactId>
        <version>5.8.0</version>
    </dependency>
    <dependency>
        <groupId>org.apache.xbean</groupId>
        <artifactId>xbean-spring</artifactId>
        <version>3.13</version>
    </dependency>
</dependencies>

Relevant section of spring config:

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:util="http://www.springframework.org/schema/util"
xmlns:security="http://www.springframework.org/schema/security"
xmlns:task="http://www.springframework.org/schema/task" xmlns:jms="http://www.springframework.org/schema/jms"
xmlns:oxm="http://www.springframework.org/schema/oxm" xmlns:amq="http://activemq.apache.org/schema/core"
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
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/security 
http://www.springframework.org/schema/security/spring-security.xsd
http://www.springframework.org/schema/task 
http://www.springframework.org/schema/task/spring-task.xsd
http://www.springframework.org/schema/jms
http://www.springframework.org/schema/jms/spring-jms.xsd
http://www.springframework.org/schema/oxm
http://www.springframework.org/schema/oxm/spring-oxm.xsd
http://activemq.apache.org/schema/core
http://activemq.apache.org/schema/core/activemq-core.xsd">

<!-- JMS -->
<amq:connectionFactory id="connectionFactory"
    brokerURL="tcp://localhost:61616" />

<bean id="cachingConnectionFactory"
    class="org.springframework.jms.connection.CachingConnectionFactory">
    <property name="targetConnectionFactory" ref="connectionFactory" />
    <property name="sessionCacheSize" value="100" />
</bean>

<!-- Integration with Focus -->
<amq:queue id="appointmentsImportQ" physicalName="FOCUS.APPOINTMENTS.EXPORT.QUEUE" />

<bean id="appointmentsImportMessageListener"
    class="com.test.authmgr.service.messaging.AppointmentsImportMessageListener">
</bean>

<bean id="appointmentsImportMsgListenerContainer"
    class="org.springframework.jms.listener.SimpleMessageListenerContainer">
    <property name="connectionFactory" ref="cachingConnectionFactory" />
    <property name="destination" ref="appointmentsImportQ" />
    <property name="messageListener" ref="appointmentsImportMessageListener" />
    <property name="concurrentConsumers" value="1" />
</bean>

<bean id="oxmAppointmentsImportMessageConverter"
    class="org.springframework.jms.support.converter.MarshallingMessageConverter">
    <property name="marshaller" ref="appointmentsImportMarshaller" />
    <property name="unmarshaller" ref="appointmentsImportMarshaller" />
</bean>

<oxm:jaxb2-marshaller id="appointmentsImportMarshaller">
    <oxm:class-to-be-bound
        name="com.test.authmgr.focus.integration.jaxb.Profile" />
</oxm:jaxb2-marshaller>
</beans>

If the spring-framework's version is lowered to say 3.1.x then I start to get ClassNotFoundException for other spring-jms stuff like MessageConverter.

I thought maybe something is wrong with the wtp plugin, however, running from the command line:

mvn clean package

results in:

package org.springframework.jms.support.converter does not exist

I can verify that the package does exist in .m2 and spring-jms-3.2.3.RELEASE.jar does contain the said package.

ActiveMQ is running as a stand alone server and I can log in http:localhost:8161/admin.

What is missing from this configuration? Any help will be greatly appreciated. Thanks.

도움이 되었습니까?

해결책

You probably have some other Spring jar versions on the classpath (maybe in one of the tomcat shared classloaders). Add -verbose to CATALINA_OPTS to see which jar(s) classes are being loaded from.

EDIT

Also take a look at the dependency graph in the eclipse POM editor - you may have to exclude Spring deps brought in transitively by other projects.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top