azerIO
azerIO

Reputation: 519

Inject singleton bean into session bean via remote interface, object always "null"

I need to inject a singleton bean into the session bean. Below are the corresponding classes. The problem is that the injected object is always null. I tried all of the JNDI lookup strings which my JBoss 7.0.1 server showed me during startup (i.e. JNDI bindings for session bean named GlobalBean in deployment unit subdeployment .. of deployment .. are as follows: ..). I also tried commenting out the @EJB annotation in GlobalBean.java and also tried to use the "ejb/GlobalBean" during injection. However, no luck. What could be the reason? Thx.

GlobalBean.java:

@Startup
@Singleton
@Remote(GlobalBeanRemote.class)
@EJB(name="ejb/GlobalBean", beanName="GlobalBean", beanInterface=GlobalBeanRemote.class)  
@ConcurrencyManagement(ConcurrencyManagementType.CONTAINER)
public class GlobalBean implements GlobalBeanRemote
{
   // CODE
}

SessionBean.java:

@Stateful
public class SessionBean extends ParentBean
{
      @EJB(name="java:module/GlobalBean!project.framework.interfaces.GlobalBeanRemote")
      private GlobalBeanRemote globalBeanAPI3;

      // CODE
}

Upvotes: 1

Views: 4070

Answers (1)

Csaba
Csaba

Reputation: 949

In your SessionBean class try changing name attribute of @EJB to mappedName.

@EJB(mappedName="java:module/GlobalBean!project.framework.interfaces.GlobalBeanRemote")

This will, of course, only work if your two beans are in the same module.

Update Given that your beans are in separate modules, try using the java:app namespace:

@EJB(mappedName="java:app ...")

The java:app namespace is used to look up local enterprise beans packaged within the same application. That is, the enterprise bean is packaged within an EAR file containing multiple Java EE modules. JNDI addresses using the java:app namespace are of the following form:

java:app[/module name]/enterprise bean name[/interface name]

Also try removing GlobalBean's @EJB annotation. @EJB is used to define a dependency.

Upvotes: 3

Related Questions