Now I get it!This seems to work fine: <?xml version="1.0" encoding="UTF-8"?><blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"> <reference id="app" interface="com.app.IApp"/> <camelContext xmlns="http://camel.apache.org/schema/blueprint"> <route> <from uri="timer:simple?period=5000"/> <bean ref="app" method="doIt"/> </route> </camelContext> </blueprint> I didn't know I could use reference to actually reference a component registered using @Component. Many thanks Paul!
El viernes, 9 de junio de 2023, 19:47:42 ART, Paul McCulloch <pkmccull...@gmail.com> escribió: Use reference to access your App component that Ds creates for you. You currently have two instances of App - one from DS and one from your <bean>. On Fri, 9 Jun 2023, 23:33 z8sbk.yahoo.com.ar via user, <user@karaf.apache.org> wrote: Hi Paul,I'm not sure what you mean with using <reference> instead of <bean>. I tried this: <?xml version="1.0" encoding="UTF-8"?><blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"> <reference id="conf" interface="com.conf.IConf"/> <bean id="app" class="com.app.App" > <property name="conf" ref="conf"/> </bean> <camelContext xmlns="http://camel.apache.org/schema/blueprint"> <route> <from uri="timer:simple?period=5000"/> <to uri="bean:app?method=doIt"/> </route> </camelContext> </blueprint> Now the error is: 19:21:14.974 ERROR [xxxx\apache-karaf-4.2.15/deploy] Unable to start container for blueprint bundle confByDS.xml/0.0.0org.osgi.service.blueprint.container.ComponentDefinitionException: Unable to find property descriptor conf on com.app.App at org.apache.aries.blueprint.container.BeanRecipe.getPropertyDescriptor(BeanRecipe.java:831) ~[!/:1.10.3] at org.apache.aries.blueprint.container.BeanRecipe.setProperty(BeanRecipe.java:813) ~[!/:1.10.3] at org.apache.aries.blueprint.container.BeanRecipe.setProperties(BeanRecipe.java:784) ~[!/:1.10.3] at org.apache.aries.blueprint.container.BeanRecipe.setProperties(BeanRecipe.java:765) ~[!/:1.10.3] at org.apache.aries.blueprint.container.BeanRecipe.internalCreate2(BeanRecipe.java:699) ~[!/:1.10.3] at org.apache.aries.blueprint.container.BeanRecipe.internalCreate(BeanRecipe.java:666) ~[!/:1.10.3] at org.apache.aries.blueprint.di.AbstractRecipe$1.call(AbstractRecipe.java:81) ~[!/:1.10.3] Could you please fix my previous blueprint? Thanks in advanced. El viernes, 9 de junio de 2023, 17:25:31 ART, Paul McCulloch <pkmccull...@gmail.com> escribió: You need to use <reference> in your blueprint to access your ds component. Using <bean> creates a new instance, but doesn't wire it into the ds infrastructure. On Fri, 9 Jun 2023, 16:22 z8sbk.yahoo.com.ar via user, <user@karaf.apache.org> wrote: Hi, I'm trying to understand how declarative service works. In a bundle, I have these two clasess, very basic: @Componentpublic class App implements IApp { @Referenceprivate IConf conf; public App() {} public void doIt() { System.out.println("foo=" + conf.getFoo()); } } @Component(name = "Conf", immediate = true, configurationPid = "confByDS")public class Conf implements IConf { private String foo = "bar"; public Conf() {}@Override public String getFoo() { return foo; } @Activate@Modifiedpublic void activate(ComponentContext context) { foo = context.getProperties().get("foo") != null ? (String) context.getProperties().get("foo") : this.foo; } } Then, I have this blueprint/camel route: <?xml version="1.0" encoding="UTF-8"?><blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"> <bean id="app" class="com.app.App" /> <camelContext xmlns="http://camel.apache.org/schema/blueprint"> <route> <from uri="timer:simple?period=5000"/> <to uri="bean:app?method=doIt"/> </route> </camelContext> </blueprint> After deploying the bundle, when I put the blueprint in /deploy, throws a NullPointerException in conf.getFoo(), which means that the Conf reference is not injected: Message History---------------------------------------------------------------------------------------------------------------------------------------RouteId ProcessorId Processor Elapsed (ms)[route3 ] [route3 ] [timer://simple?period=5000 ] [ 7][route3 ] [to2 ] [bean:app?method=doIt ] [ 0] Stacktrace---------------------------------------------------------------------------------------------------------------------------------------java.lang.NullPointerException: null at com.app.App.doIt(App.java:17) ~[!/:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_321] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_321] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_321] I think I'm misunderstanding how the DI in Karaf works plus DS, could you please tell me what am I missing? Does DS work with Camel XML DSL routes? Thanks in advanced.Nick.