Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
@Reference not working inside the *serviceImpl
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
}
}
}