-
1. Re: Injecting CDI Bean into Camel RouteBuilder
igarashitm Dec 6, 2015 8:19 PM (in response to ozkin)You may want to take a look at this quickstart - https://github.com/jboss-switchyard/switchyard/blob/master/quickstarts/demos/multiApp/web/src/main/resources/META-INF/switchyard.xml
It's injecting SwitchYard service reference into ItemEntry, a plain CDI bean. Note that the ItemEntry is specified as a SwitchYard bean service in the switchyard.xml. It's required to get service reference injected.
However, if you just want to use that bean as a plain CDI bean but not as a SwitchYard service reference, then you just need to add @Named onto that CDI bean and use bean ref in the route.
-
2. Re: Injecting CDI Bean into Camel RouteBuilder
ozkin Dec 7, 2015 3:11 AM (in response to igarashitm)Yes, the idea was to use a bean as a plain CDI bean. And I know that .to("bean: and .bean( works fine in Camel route. But intention was to use a bean as a java object in the code, as I demonstrated in the original post. Imagine there is more complex logic and you need to invoke different methods on a bean inside the route, say inside Processor(), or inside different statements, like setHeader(), setBody(), to() and whatnot. Sometimes it might be useful when such a bean represents a configuration service and you are getting different parameters.
I could solve this issue by doing: private InternalService service = new InternalService();
but I wanted to do this with injection instead.
-
3. Re: Injecting CDI Bean into Camel RouteBuilder
igarashitm Dec 7, 2015 9:01 PM (in response to ozkin)It's not possible right now because SwitchYard runtime instantiates the RouteBuilder class directly. In order to do that we would need to add an option to lookup a RouteBuilder instance from BeanManager like we're already doing for transformer/validator. Feel free to file a enhancement JIRA.