java - Camel ProducerTemplate not injected with annotation config -
first of all, know there similar questions (camel producertemplate not injected in spring mvc , initializing camel spring annotation config) don't in case.
i have bean sends messages producertemplate:
public class simpleproducer { @produce(uri = "activemq:queue:simple") private producertemplate activemqproducer; public void send(string message) { activemqproducer.sendbody(message); } }
when use annotation driven configuration below, trhows npe send method (activemqproducer not injected):
@configuration public class annotationconfigapp { public static void main(string[] args) { applicationcontext context = new annotationconfigapplicationcontext(annotationconfigapp.class); simpleproducer simpleproducer = context.getbean(simpleproducer.class); simpleproducer.send("hello world!"); } @autowired private applicationcontext ctx; @bean public simpleproducer simpleproducer() { return new simpleproducer(); } @bean public camelcontext camelcontext() throws exception { camelcontext camelcontext = new springcamelcontext(ctx); camelcontext.start(); return camelcontext; } }
while using equivalent (at least believe so) xml configuration, sucessfully sends message activemq:
<?xml version="1.0" encoding="utf-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:spring="http://camel.apache.org/schema/spring" 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="simpleproducer" class="makasprzak.so.camel.producer.testing.simpleproducer"/> <spring:camelcontext xmlns="http://camel.apache.org/schema/spring" id="simple.sender" /> </beans>
initialized this:
public class xmlconfigapp { public static void main(string[] args) { applicationcontext context = new genericxmlapplicationcontext("context.xml"); simpleproducer simpleproducer = context.getbean(simpleproducer.class); simpleproducer.send("hello world!"); } }
i've been playing camelcontext implementation bit, tried defaultcamelcontext or springcamelcontextfactory - no luck.
the problematic code available in github
<properties> <camel.version>2.15.2</camel.version> <activemq.version>5.10.0</activemq.version> <java.version>1.8</java.version> </properties>
what did miss in annotation configuration?
you should extend org.apache.camel.spring.javaconfig.camelconfiguration in annotationconfigapp class
Comments
Post a Comment