Injected @EJB is null in @Service Singleton's constructor in JBoss EAP 5.x
Issue
I have a JBoss Singleton implemented with @Service annotation, which uses the @EJB annotation to inject an EJB reference. The injected EJB variable is being used in the constructor. When it deploys, it throws a null pointer exception (NullPointerException). How do I specify that this service is dependent on the EJB? I thought the @EJB handled that. See Example code:
import org.jboss.ejb3.annotation.Service;
import javax.ejb.EJB;
@Service
public class ExampleService{
@EJB
ExampleEJB ejb;
public ExampleService(){
ejb.hello(); // getting null pointer here
}
}
Environment
- JBoss Enterprise Application Platform (EAP)
- 5.x
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase of over 48,000 articles and solutions.
Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.
