@Reference not working inside the *serviceImpl

Vishnu S Kumar, modified 3 Years ago. Regular Member Posts: 131 Join Date: 7/28/17 Recent Posts

Inside the service builder *serviceImpl class, the @Reference annotation gives a null value and there is a catch here.When the impl class first activates (inside the @activate function), the @reference annotations works. But later, when we call a method inside the service, @reference dependency is null.
 

public interface Base{}

................

@component(service = Base.class)

public class Parent implements Base{}

..................

@Component(.......)
public class testServiceImpl{

    @Reference
    private volatile Base b;
    
    public void doSomething(){
        
     b.test(); // null point exception
    
    }

    @Activate
    @Modified
    protected void activate(Map<String, Object> properties)
	{
      b.test(); // works here 
    }
    }

}