SpringBoot Camel SendBody() 路由不发送
Posted
技术标签:
【中文标题】SpringBoot Camel SendBody() 路由不发送【英文标题】:SpringBoot Camel SendBody() routes not sending 【发布时间】:2017-05-28 13:34:34 【问题描述】:我正在尝试创建一个 SpringBoot Camel 应用程序(用于测试)。我已经配置了 SpringBoot 和 Camel-Spring。似乎它正在工作,但不知何故它无法将数据发送到 activemq(通过 SendBody)。
applicationContext.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
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
<bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="configuration" ref="jmsConfig"/>
</bean>
<bean id="jmsConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="failover:(tcp://localhost:61616)"/>
<property name="useAsyncSend" value="true"/>
<property name="watchTopicAdvisories" value="false"/>
</bean>
<bean id="pooledConnectionFactory" class="org.apache.activemq.pool.PooledConnectionFactory"
init-method="start" destroy-method="stop">
<property name="maxConnections" value="8" />
<property name="connectionFactory" ref="jmsConnectionFactory" />
</bean>
<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory" ref="pooledConnectionFactory" />
</bean>
<camelContext id="camelContext" xmlns="http://camel.apache.org/schema/spring" allowUseOriginalMessage="false">
<jmxAgent id="agent" disabled="true"/>
<route>
<from uri="direct:a" />
<to uri="activemq:queue:ingest.Queue" />
</route>
</camelContext>
主应用 它在 template.sendBody() 失败
package com.sis.klaver;
import org.apache.camel.CamelContext;
import org.apache.camel.ProducerTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
@SpringBootApplication
public class MainApp
public static void main(String[] args)
SpringApplication.run(MainApp.class, args);
@Autowired
private CamelContext camelContext;
@Bean
public String DoThis(ApplicationContext ctx)
ProducerTemplate template = camelContext.createProducerTemplate();
template.sendBody("direct:a", "blah blah blah");
return "one";
错误信息
. ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_||))))) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|===============|___/=/_/_/_/ :: Spring Boot :: (v1.4.3.RELEASE) 2017-01-13 16:17:25.565 INFO 13984 --- [main] com.sis.klaver.MainApp :在具有 PID 13984 的 Lenovo-PC 上启动 MainApp(D:\newklaver\cameldemo\target\classes 由用户在D:\newklaver\cameldemo) 2017-01-13 16:17:25.567 INFO 13984 --- [main] com.sis.klaver.MainApp:未设置活动配置文件,回退到默认配置文件:默认 2017-01-13 16:17:25.615 INFO 13984 --- [main] ationConfigEmbeddedWebApplicationContext:刷新 org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@3c407114:启动日期 [Fri Jan 13 16:17:25 SGT 2017];上下文层次的根 2017-01-13 16:17:26.629 INFO 13984 --- [main] trationDelegate$BeanPostProcessorChecker:Bean 'org.apache.camel.spring.boot.CamelAutoConfiguration' 类型 [class org.apache.camel.spring.boot. CamelAutoConfiguration$$EnhancerBySpringCGLIB$$$670d656] 不符合被所有 BeanPostProcessors 处理的条件(例如:不符合自动代理的条件) 2017-01-13 16:17:27.058 INFO 13984 --- [main] s.b.c.e.t.TomcatEmbeddedServletContainer:Tomcat 使用端口初始化:8080 (http) 2017-01-13 16:17:27.072 INFO 13984 --- [main] o.apache.catalina.core.StandardService:启动服务 Tomcat 2017-01-13 16:17:27.074 INFO 13984 --- [main] org.apache.catalina.core.StandardEngine:启动 Servlet 引擎:Apache Tomcat/8.5.6 2017-01-13 16:17:27.176 INFO 13984 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]:初始化 Spring 嵌入式 WebApplicationContext 2017-01-13 16:17:27.176 INFO 13984 --- [ost-startStop-1] os.web.context.ContextLoader:根 WebApplicationContext:初始化在 1565 毫秒内完成 2017-01-13 16:17:27.316 信息 13984 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean:映射 servlet:'dispatcherServlet' 到 [/] 2017-01-13 16:17:27.320 信息 13984 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean:映射过滤器:'characterEncodingFilter' 到:[/*] 2017-01-13 16:17:27.320 信息 13984 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean:映射过滤器:'hiddenHttpMethodFilter' 到:[/*] 2017-01-13 16:17:27.320 信息 13984 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean:映射过滤器:“httpPutFormContentFilter”到:[/*] 2017-01-13 16:17:27.320 信息 13984 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean:映射过滤器:'requestContextFilter' 到:[/*] 2017-01-13 16:17:27.816 INFO 13984 --- [main] o.a.c.i.converter.DefaultTypeConverter:加载了 190 个类型转换器 2017-01-13 16:17:27.835 WARN 13984 --- [main] ationConfigEmbeddedWebApplicationContext:在上下文初始化期间遇到异常-取消刷新尝试:org.springframework.beans.factory.BeanCreationException:创建名称为“DoThis”的bean时定义在com.sis.klaver.MainApp:通过工厂方法进行 Bean 实例化失败;嵌套异常是 org.springframework.beans.BeanInstantiationException:无法实例化 [java.lang.String]:工厂方法“DoThis”抛出异常;嵌套异常是 org.apache.camel.CamelExecutionException:在交换执行期间发生异常:Exchange[ID-Lenovo-PC-58679-1484295447423-0-2] 2017-01-13 16:17:27.836 INFO 13984 --- [main] o.a.camel.spring.SpringCamelContext:Apache Camel 2.18.1(CamelContext:camel-1)正在关闭 2017-01-13 16:17:27.847 INFO 13984 --- [main] o.a.camel.spring.SpringCamelContext:Apache Camel 2.18.1 (CamelContext: camel-1) 正常运行时间 2017-01-13 16:17:27.848 INFO 13984 --- [main] o.a.camel.spring.SpringCamelContext:Apache Camel 2.18.1(CamelContext:camel-1)在 0.011 秒内关闭 2017-01-13 16:17:27.850 INFO 13984 --- [main] o.apache.catalina.core.StandardService:停止服务 Tomcat 2017-01-13 16:17:27.859 信息 13984 --- [主要] utoConfigurationReportLoggingInitializer: 启动 ApplicationContext 时出错。要显示自动配置报告,请在启用“调试”的情况下重新运行您的应用程序。 2017-01-13 16:17:27.864 错误 13984 --- [main] os.boot.SpringApplication:应用程序启动失败 org.springframework.beans.factory.BeanCreationException:创建 com.sis.klaver.MainApp 中定义的名称为“DoThis”的 bean 时出错:通过工厂方法进行 Bean 实例化失败;嵌套异常是 org.springframework.beans.BeanInstantiationException:无法实例化 [java.lang.String]:工厂方法“DoThis”抛出异常;嵌套异常是 org.apache.camel.CamelExecutionException:在交换执行期间发生异常:Exchange[ID-Lenovo-PC-58679-1484295447423-0-2] 在 org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE] 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1134) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE] 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1028) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE] 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE] 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE] 在 org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE] 在 org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE] 在 org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE] 在 org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE] 在 org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:759) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE] 在 org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:866) ~[spring-context-4.3.5.RELEASE.jar:4.3.5.RELEASE] 在 org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542) ~[spring-context-4.3.5.RELEASE.jar:4.3.5.RELEASE] 在 org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.4.3.RELEASE.jar:1.4.3.RELEASE] 在 org.springframework.boot.SpringApplication.refresh(SpringApplication.java:761) [spring-boot-1.4.3.RELEASE.jar:1.4.3.RELEASE] 在 org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:371) [spring-boot-1.4.3.RELEASE.jar:1.4.3.RELEASE] 在 org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-1.4.3.RELEASE.jar:1.4.3.RELEASE] 在 org.springframework.boot.SpringApplication.run(SpringApplication.java:1186) [spring-boot-1.4.3.RELEASE.jar:1.4.3.RELEASE] 在 org.springframework.boot.SpringApplication.run(SpringApplication.java:1175) [spring-boot-1.4.3.RELEASE.jar:1.4.3.RELEASE] 在 com.sis.klaver.MainApp.main(MainApp.java:17) [classes/:na] 在 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_101] 在 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_101] 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_101] 在 java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_101] 在 com.intellij.rt.execution.application.AppMain.main(AppMain.java:147) [idea_rt.jar:na] 原因:org.springframework.beans.BeanInstantiationException:无法实例化[java.lang.String]:工厂方法'DoThis'抛出异常;嵌套异常是 org.apache.camel.CamelExecutionException:在交换执行期间发生异常:Exchange[ID-Lenovo-PC-58679-1484295447423-0-2] 在 org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE] 在 org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE] ...省略了23个常用框架 原因:org.apache.camel.CamelExecutionException:在交易所执行期间发生异常:Exchange[ID-Lenovo-PC-58679-1484295447423-0-2] 在 org.apache.camel.util.ObjectHelper.wrapCamelExecutionException(ObjectHelper.java:1779) ~[camel-core-2.18.1.jar:2.18.1] 在 org.apache.camel.util.ExchangeHelper.extractResultBody(ExchangeHelper.java:677) ~[camel-core-2.18.1.jar:2.18.1] 在 org.apache.camel.impl.DefaultProducerTemplate.extractResultBody(DefaultProducerTemplate.java:515) ~[camel-core-2.18.1.jar:2.18.1] 在 org.apache.camel.impl.DefaultProducerTemplate.extractResultBody(DefaultProducerTemplate.java:511) ~[camel-core-2.18.1.jar:2.18.1] 在 org.apache.camel.impl.DefaultProducerTemplate.sendBody(DefaultProducerTemplate.java:163) ~[camel-core-2.18.1.jar:2.18.1] 在 org.apache.camel.impl.DefaultProducerTemplate.sendBody(DefaultProducerTemplate.java:168) ~[camel-core-2.18.1.jar:2.18.1] 在 com.sis.klaver.MainApp.DoThis(MainApp.java:26) [classes/:na] 在 com.sis.klaver.MainApp$$EnhancerBySpringCGLIB$$ed6265d7.CGLIB$DoThis$0() ~[classes/:na] 在 com.sis.klaver.MainApp$$EnhancerBySpringCGLIB$$ed6265d7$$FastClassBySpringCGLIB$$233a5f2b.invoke() ~[classes/:na] 在 org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-4.3.5.RELEASE.jar:4.3.5.RELEASE] 在 org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:356) ~[spring-context-4.3.5.RELEASE.jar:4.3.5.RELEASE] 在 com.sis.klaver.MainApp$$EnhancerBySpringCGLIB$$ed6265d7.DoThis() ~[classes/:na] 在 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_101] 在 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_101] 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_101] 在 java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_101] 在 org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE] ...省略了24个常用框架 引起:org.apache.camel.component.direct.DirectConsumerNotAvailableException:端点上没有可用的消费者:direct://a。交换[ID-Lenovo-PC-58679-1484295447423-0-2] 在 org.apache.camel.component.direct.DirectProducer.process(DirectProducer.java:55) ~[camel-core-2.18.1.jar:2.18.1] 在 org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:197) ~[camel-core-2.18.1.jar:2.18.1] 在 org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:97) ~[camel-core-2.18.1.jar:2.18.1] 在 org.apache.camel.impl.ProducerCache$1.doInProducer(ProducerCache.java:529) ~[camel-core-2.18.1.jar:2.18.1] 在 org.apache.camel.impl.ProducerCache$1.doInProducer(ProducerCache.java:497) ~[camel-core-2.18.1.jar:2.18.1] 在 org.apache.camel.impl.ProducerCache.doInProducer(ProducerCache.java:365) ~[camel-core-2.18.1.jar:2.18.1] 在 org.apache.camel.impl.ProducerCache.sendExchange(ProducerCache.java:497) ~[camel-core-2.18.1.jar:2.18.1] 在 org.apache.camel.impl.ProducerCache.send(ProducerCache.java:225) ~[camel-core-2.18.1.jar:2.18.1] 在 org.apache.camel.impl.DefaultProducerTemplate.send(DefaultProducerTemplate.java:144) ~[camel-core-2.18.1.jar:2.18.1] 在 org.apache.camel.impl.DefaultProducerTemplate.sendBody(DefaultProducerTemplate.java:161) ~[camel-core-2.18.1.jar:2.18.1] ...省略了36个常用框架 进程以退出代码 1 结束有人知道为什么它不起作用吗?对于我阅读过的文档,它应该可以工作。
谢谢。
在添加 @ImportResource... 正如 Hassen Bennour 所建议的那样 我得到了这个错误。一些错误仍然在同一个地方
2017-01-13 17:10:26.970 INFO 8960 --- [main] com.sis.klaver.MainApp:在 PID 8960 的 Lenovo-PC 上启动 MainApp(D:\newklaver\cameldemo\target\classes 由用户在D:\newklaver\cameldemo) 2017-01-13 17:10:26.972 INFO 8960 --- [main] com.sis.klaver.MainApp:未设置活动配置文件,回退到默认配置文件:默认 2017-01-13 17:10:27.039 INFO 8960 --- [main] ationConfigEmbeddedWebApplicationContext:刷新 org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@f5ac9e4:启动日期 [Fri Jan 13 17:10:27 SGT 2017];上下文层次的根 2017-01-13 17:10:27.648 INFO 8960 --- [main] o.s.b.f.xml.XmlBeanDefinitionReader:从类路径资源 [applicationContext.xml] 加载 XML bean 定义 2017-01-13 17:10:28.767 INFO 8960 --- [main] trationDelegate$BeanPostProcessorChecker:Bean 'org.apache.camel.spring.boot.CamelAutoConfiguration' 类型 [class org.apache.camel.spring.boot. CamelAutoConfiguration$$EnhancerBySpringCGLIB$$e2eb989a] 不符合被所有 BeanPostProcessors 处理的条件(例如:不符合自动代理的条件) 2017-01-13 17:10:29.146 INFO 8960 --- [main] s.b.c.e.t.TomcatEmbeddedServletContainer:Tomcat 使用端口初始化:8080 (http) 2017-01-13 17:10:29.159 INFO 8960 --- [main] o.apache.catalina.core.StandardService:启动服务 Tomcat 2017-01-13 17:10:29.160 INFO 8960 --- [main] org.apache.catalina.core.StandardEngine:启动 Servlet 引擎:Apache Tomcat/8.5.6 2017-01-13 17:10:29.268 INFO 8960 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]:初始化 Spring 嵌入式 WebApplicationContext 2017-01-13 17:10:29.268 INFO 8960 --- [ost-startStop-1] os.web.context.ContextLoader:根 WebApplicationContext:初始化在 2233 毫秒内完成 2017-01-13 17:10:29.396 INFO 8960 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean:映射 servlet:'dispatcherServlet' 到 [/] 2017-01-13 17:10:29.399 信息 8960 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean:映射过滤器:'characterEncodingFilter' 到:[/*] 2017-01-13 17:10:29.400 INFO 8960 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean:映射过滤器:'hiddenHttpMethodFilter' 到:[/*] 2017-01-13 17:10:29.400 信息 8960 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean:映射过滤器:“httpPutFormContentFilter”到:[/*] 2017-01-13 17:10:29.400 信息 8960 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean:映射过滤器:'requestContextFilter' 到:[/*] 2017-01-13 17:10:29.843 信息 8960 --- [主要].a.c.c.x.AbstractCamelContextFactoryBean:JMXAgent 已禁用 2017-01-13 17:10:29.912 INFO 8960 --- [main] o.a.c.i.converter.DefaultTypeConverter:加载了 193 个类型转换器 2017-01-13 17:10:29.931 WARN 8960 --- [main] ationConfigEmbeddedWebApplicationContext:在上下文初始化期间遇到异常-取消刷新尝试:org.springframework.beans.factory.BeanCreationException:创建名称为“DoThis”的bean时定义在com.sis.klaver.MainApp:通过工厂方法进行 Bean 实例化失败;嵌套异常是 org.springframework.beans.BeanInstantiationException:无法实例化 [java.lang.String]:工厂方法“DoThis”抛出异常;嵌套异常是 org.apache.camel.CamelExecutionException:在交换执行期间发生异常:Exchange[ID-Lenovo-PC-59078-1484298629534-0-2] 2017-01-13 17:10:29.931 INFO 8960 --- [main] o.a.camel.spring.SpringCamelContext:Apache Camel 2.18.1(CamelContext:camelContext)正在关闭 2017-01-13 17:10:29.943 INFO 8960 --- [main] o.a.camel.spring.SpringCamelContext:Apache Camel 2.18.1(CamelContext:camelContext)正常运行时间 2017-01-13 17:10:29.943 INFO 8960 --- [main] o.a.camel.spring.SpringCamelContext:Apache Camel 2.18.1(CamelContext:camelContext)在 0.012 秒内关闭 2017-01-13 17:10:29.945 INFO 8960 --- [main] o.apache.catalina.core.StandardService:停止服务 Tomcat 2017-01-13 17:10:29.958 WARN 8960 --- [main] osboot.SpringApplication:错误处理失败(创建名为“camelContext”的 bean 时出错:调用 init 方法失败;嵌套异常是 java.lang.IllegalStateException : org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@f5ac9e4 尚未刷新) 2017-01-13 17:10:29.963 错误 8960 --- [main] os.boot.SpringApplication:应用程序启动失败 org.springframework.beans.factory.BeanCreationException:创建 com.sis.klaver.MainApp 中定义的名称为“DoThis”的 bean 时出错:通过工厂方法进行 Bean 实例化失败;嵌套异常是 org.springframework.beans.BeanInstantiationException:无法实例化 [java.lang.String]:工厂方法“DoThis”抛出异常;嵌套异常是 org.apache.camel.CamelExecutionException:在交换执行期间发生异常:Exchange[ID-Lenovo-PC-59078-1484298629534-0-2] 在 org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE] 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1134) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE] 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1028) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE] 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE] 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE] 在 org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE] 在 org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE] 在 org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE] 在 org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE] 在 org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:759) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE] 在 org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:866) ~[spring-context-4.3.5.RELEASE.jar:4.3.5.RELEASE] 在 org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542) ~[spring-context-4.3.5.RELEASE.jar:4.3.5.RELEASE] 在 org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.4.3.RELEASE.jar:1.4.3.RELEASE] 在 org.springframework.boot.SpringApplication.refresh(SpringApplication.java:761) [spring-boot-1.4.3.RELEASE.jar:1.4.3.RELEASE] 在 org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:371) [spring-boot-1.4.3.RELEASE.jar:1.4.3.RELEASE] 在 org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-1.4.3.RELEASE.jar:1.4.3.RELEASE] 在 org.springframework.boot.SpringApplication.run(SpringApplication.java:1186) [spring-boot-1.4.3.RELEASE.jar:1.4.3.RELEASE] 在 org.springframework.boot.SpringApplication.run(SpringApplication.java:1175) [spring-boot-1.4.3.RELEASE.jar:1.4.3.RELEASE] 在 com.sis.klaver.MainApp.main(MainApp.java:17) [classes/:na] 在 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_101] 在 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_101] 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_101] 在 java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_101] 在 com.intellij.rt.execution.application.AppMain.main(AppMain.java:147) [idea_rt.jar:na] 原因:org.springframework.beans.BeanInstantiationException:无法实例化[java.lang.String]:工厂方法'DoThis'抛出异常;嵌套异常是 org.apache.camel.CamelExecutionException:在交换执行期间发生异常:Exchange[ID-Lenovo-PC-59078-1484298629534-0-2] 在 org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE] 在 org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE] ...省略了23个常用框架 原因:org.apache.camel.CamelExecutionException:在交易所执行期间发生异常:Exchange[ID-Lenovo-PC-59078-1484298629534-0-2] 在 org.apache.camel.util.ObjectHelper.wrapCamelExecutionException(ObjectHelper.java:1779) ~[camel-core-2.18.1.jar:2.18.1] 在 org.apache.camel.util.ExchangeHelper.extractResultBody(ExchangeHelper.java:677) ~[camel-core-2.18.1.jar:2.18.1] 在 org.apache.camel.impl.DefaultProducerTemplate.extractResultBody(DefaultProducerTemplate.java:515) ~[camel-core-2.18.1.jar:2.18.1] 在 org.apache.camel.impl.DefaultProducerTemplate.extractResultBody(DefaultProducerTemplate.java:511) ~[camel-core-2.18.1.jar:2.18.1] 在 org.apache.camel.impl.DefaultProducerTemplate.sendBody(DefaultProducerTemplate.java:163) ~[camel-core-2.18.1.jar:2.18.1] 在 org.apache.camel.impl.DefaultProducerTemplate.sendBody(DefaultProducerTemplate.java:168) ~[camel-core-2.18.1.jar:2.18.1] 在 com.sis.klaver.MainApp.DoThis(MainApp.java:23) [classes/:na] 在 com.sis.klaver.MainApp$$EnhancerBySpringCGLIB$$c9dd281b.CGLIB$DoThis$0() ~[classes/:na] 在 com.sis.klaver.MainApp$$EnhancerBySpringCGLIB$$c9dd281b$$FastClassBySpringCGLIB$$c209c90b.invoke() ~[classes/:na] 在 org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-4.3.5.RELEASE.jar:4.3.5.RELEASE] 在 org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:356) ~[spring-context-4.3.5.RELEASE.jar:4.3.5.RELEASE] 在 com.sis.klaver.MainApp$$EnhancerBySpringCGLIB$$c9dd281b.DoThis() ~[classes/:na] 在 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_101] 在 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_101] 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_101] 在 java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_101] 在 org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE] ...省略了24个常用框架 引起:org.apache.camel.component.direct.DirectConsumerNotAvailableException:端点上没有可用的消费者:direct://a。交换[ID-Lenovo-PC-59078-1484298629534-0-2] 在 org.apache.camel.component.direct.DirectProducer.process(DirectProducer.java:55) ~[camel-core-2.18.1.jar:2.18.1] 在 org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:197) ~[camel-core-2.18.1.jar:2.18.1] 在 org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:97) ~[camel-core-2.18.1.jar:2.18.1] 在 org.apache.camel.impl.ProducerCache$1.doInProducer(ProducerCache.java:529) ~[camel-core-2.18.1.jar:2.18.1] 在 org.apache.camel.impl.ProducerCache$1.doInProducer(ProducerCache.java:497) ~[camel-core-2.18.1.jar:2.18.1] 在 org.apache.camel.impl.ProducerCache.doInProducer(ProducerCache.java:365) ~[camel-core-2.18.1.jar:2.18.1] 在 org.apache.camel.impl.ProducerCache.sendExchange(ProducerCache.java:497) ~[camel-core-2.18.1.jar:2.18.1] 在 org.apache.camel.impl.ProducerCache.send(ProducerCache.java:225) ~[camel-core-2.18.1.jar:2.18.1] 在 org.apache.camel.impl.DefaultProducerTemplate.send(DefaultProducerTemplate.java:144) ~[camel-core-2.18.1.jar:2.18.1] 在 org.apache.camel.impl.DefaultProducerTemplate.sendBody(DefaultProducerTemplate.java:161) ~[camel-core-2.18.1.jar:2.18.1] ...省略了36个常用框架 进程以退出代码 1 结束【问题讨论】:
【参考方案1】:直接路由:a 未启动
像这样添加@ImportResource
@SpringBootApplication
@ImportResource("classpath:applicationContext.xml")
public class MainApp
更新
如果可以,请删除 @Bean 和参数,并通过另一种方式调用 DoThis
,因为我认为 xml 导入是在带注释的配置之后完成的,并且 DoThis 中的发件人尝试在此之前发送消费者变得活跃。
//@Bean
public String DoThis()
或更新发送以阻止如下:
template.sendBody("direct:a?block=true", "blah blah blah");
block : Default=false, Camel 2.11.1:如果将消息发送到没有活动消费者的直接端点,那么我们可以告诉生产者阻塞并等待消费者成为活跃。
【讨论】:
感谢 Hassen,它解决了一个问题,另一个问题浮出水面。我做错了什么? 感谢 Hassen,您的代码帮助我推动了它,但我遇到了更多问题。所以在困惑了 2 天之后,我决定放弃使用 Spring Boot,尝试这样做只是没有效率。我只是要创建一个camel-spring main 然后运行它。 我认为在骆驼的情况下最好只使用xml或带注释的配置以上是关于SpringBoot Camel SendBody() 路由不发送的主要内容,如果未能解决你的问题,请参考以下文章
Spring Boot + Apache Camel + Freemarker 自定义模板加载器
spring boot + apache camel + mongodb 集成问题
springboot 整合 apache camel实现企业级数据集成和处理