I've tried putting the remote interface of another Singleton bean into another. However, the remote object will always be null. Is there any other way I could get around it?
@Singleton
public class SingletonBean1 implements SingletonBean1Remote {
开发者_StackOverflow中文版 @EJB
SingletonBean2Remote singletonBean2Remote;
...
public SingletonBean1() {
...
singletonBean2Remote.anyMethod(); // returns NullPointerException
...
}
}
The fact that it's a Singleton is immaterial. You have to initialize that reference to point to something besides null. As written, that's exactly what should happen.
The method that creates singleton #1 should get a reference to singleton #2.
I know this is an old question but dependency injection occurs AFTER the constructor has completed. So in the example above the bean will always be null in the constructor
精彩评论