Hi Nick,

Please use the users mailing list for this kind of question (dev
mailing list is more for discussions between Karaf developers).

FYI,, I think I already replied to you as private message :)

Regards
JB

On Tue, Jun 6, 2023 at 3:31 PM z8...@yahoo.com.ar.INVALID
<z8...@yahoo.com.ar.invalid> wrote:
>
> I'm trying to understand how those annotations work.I have the following 
> Activator.class and MyConf.class in the same bundle.
> The Activator code:
> @Component@Slf4jpublic class Activator implements BundleActivator, 
> ManagedService {
> private static Logger logger = 
> LoggerFactory.getLogger(Activator.class);private static final String 
> CONFIG_PID = "mytest";private ServiceRegistration serviceReg;
> @Referenceprivate MyConf conf;    public void start(BundleContext context) {  
>  Hashtable<String, Object> properties = new Hashtable<String, 
> Object>();properties.put(Constants.SERVICE_PID, CONFIG_PID);serviceReg = 
> context.registerService(ManagedService.class.getName(), this , properties); } 
>        public void stop(BundleContext context) {serviceReg.unregister();    } 
>       @SuppressWarnings("rawtypes")    @Override    public void 
> updated(Dictionary config) throws ConfigurationException {if (config == null) 
> {return;}conf.setFoo((String) config.get("foo"));conf.refresh();    }
>
> and MyConf:
> @Componentpublic class MyConf {private String foo = "bar";public MyConf() 
> {}public String getFoo() {return foo;}
> public void setFoo(String foo) {this.foo = foo;}public void refresh() 
> {System.out.println("foo=" + this.foo);}
> }
> It seems pretty basic, but when I deploy it in Karaf says:
> Status: WaitingDeclarative 
> Servicesar.com.aerolineas.esb.operaciones.pruebas.Activator (21)  missing 
> references: conf
> and in the log, there's a NullPointerException at conf.setFoo in the 
> Activator, as if the framework never instantiate + inject MyConf. Am I 
> missing something?
> Thanks in advaced.Nick.
>

Reply via email to