就像标题提到的那样,我必须通过spring与活动的mq组件进行驼峰会话。 有了这个我在找到正确的上下文使用时遇到了一些困难,我不能使用javaapplication上下文,因为它不再适用于spring版本(3.0.0.3m或者其他任何不存在的东西)而且我不能使用ClassPathXmlApplicationContext,因为它没有找到PlatformTransactionManager的
package mypack;
import org.apache.camel.CamelContext;
import org.apache.camel.Endpoint;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.jms.JmsComponent;
import org.apache.camel.impl.DefaultCamelContext;
import javax.jms.ConnectionFactory;
import javax.jms.Session;
import javax.swing.Spring;
import org.apache.activemq.camel.component.*;
import org.apache.camel.converter.jaxb.JaxbDataFormat;
import org.apache.camel.model.dataformat.BindyType;
import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
import org.springframework.config.java.context.JavaConfigApplicationContext;
import org.springframework.transaction.PlatformTransactionManager;
public class Myclass {
public static void main(String args[]) throws Exception {
CamelContext context = new DefaultCamelContext();
@SuppressWarnings("resource")
ClassPathXmlApplicationContext context2 = new ClassPathXmlApplicationContext("Spring.xml");
PlatformTransactionManager transactionManager = (PlatformTransactionManager) context2.getBean("jmsTransactionManager");
ConnectionFactory connectionFactory = (ConnectionFactory) context2.getBean("jmsConnectionFactory");
JmsComponent component = JmsComponent.jmsComponentTransacted(connectionFactory, transactionManager);
context.addComponent("activemq", component);
context.addRoutes(new RouteBuilder() {
public void configure(){
from("mock:quote").transacted().to("mock:class");
}
});
context.start();
Thread.sleep(10000);
context.stop();
}
}
我为这篇文章部分删除了我的路线,因为这不是问题所在.. 这就是我得到的错误:
2015-09-14 16:56:19,625 [main ] INFO ClassPathXmlApplicationContext - Refreshing org.apache.xbean.spring.context.ClassPathXmlApplicationContext@246ae04d: startup date [Mon Sep 14 16:56:19 CEST 2015]; root of context hierarchy
2015-09-14 16:56:19,665 [main ] INFO XBeanXmlBeanDefinitionReader - Loading XML bean definitions from class path resource [Spring.xml]
[main] INFO org.apache.camel.impl.DefaultCamelContext - Apache Camel 2.15.3 (CamelContext: camel-1) is starting
[main] INFO org.apache.camel.management.ManagedManagementStrategy - JMX is enabled
[main] INFO org.apache.camel.impl.converter.DefaultTypeConverter - Loaded 186 type converters
[main] INFO org.apache.camel.impl.DefaultCamelContext - Apache Camel 2.15.3 (CamelContext: camel-1) is shutting down
[main] INFO org.apache.camel.impl.DefaultCamelContext - Apache Camel 2.15.3 (CamelContext: camel-1) uptime 0.247 seconds
[main] INFO org.apache.camel.impl.DefaultCamelContext - Apache Camel 2.15.3 (CamelContext: camel-1) is shutdown in 0.003 seconds
Exception in thread "main" org.apache.camel.FailedToCreateRouteException: Failed to create route route1 at: >>> Transacted[] <<< in route: Route(route1)[[From[mock:quote]] -> [... because of No bean could be found in the registry of type: PlatformTransactionManager
at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:1028)
at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:185)
at org.apache.camel.impl.DefaultCamelContext.startRoute(DefaultCamelContext.java:841)
at org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamelContext.java:2911)
at org.apache.camel.impl.DefaultCamelContext.doStartCamel(DefaultCamelContext.java:2634)
at org.apache.camel.impl.DefaultCamelContext.access$000(DefaultCamelContext.java:167)
at org.apache.camel.impl.DefaultCamelContext$2.call(DefaultCamelContext.java:2483)
at org.apache.camel.impl.DefaultCamelContext$2.call(DefaultCamelContext.java:2479)
at org.apache.camel.impl.DefaultCamelContext.doWithDefinedClassLoader(DefaultCamelContext.java:2502)
at org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:2479)
at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61)
at org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:2448)
at mypack.Myclass.main(Myclass.java:42)
Caused by: org.apache.camel.NoSuchBeanException: No bean could be found in the registry of type: PlatformTransactionManager
at org.apache.camel.model.TransactedDefinition.doResolvePolicy(TransactedDefinition.java:231)
at org.apache.camel.model.TransactedDefinition.resolvePolicy(TransactedDefinition.java:165)
at org.apache.camel.model.TransactedDefinition.createProcessor(TransactedDefinition.java:142)
at org.apache.camel.model.ProcessorDefinition.makeProcessor(ProcessorDefinition.java:505)
at org.apache.camel.model.ProcessorDefinition.addRoutes(ProcessorDefinition.java:217)
at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:1025)
... 12 more
当然还有我的Spring.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="poolConnectionFactory" class="org.apache.activemq.pool.PooledConnectionFactory">
<property name="connectionFactory" ref="jmsConnectionFactory" />
</bean>
<bean id="jmsTransactionManager"
class="org.springframework.jms.connection.JmsTransactionManager">
<property name="connectionFactory" ref="jmsConnectionFactory" />
</bean>
<bean id="jmsConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="tcp://localhost:61616" />
</bean>
<bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="connectionFactory" ref="poolConnectionFactory" />
<property name="transacted" value="true" />
<property name="transactionManager" ref="jmsTransactionManager" />
</bean>
所以我的问题是如何修复它,我可以使用另一个上下文吗?(只是ApplicatonContext没有工作)或者我必须在spring.xml中添加一些内容吗?到目前为止我需要的所有依赖项都是最新版本(4.2.1.RELEASE),所以想到任何想法吗?欢迎大家帮助:)