# @EJB vs @Resource



## PollerJava (11. Feb 2015)

Hallo,

ich hätte noch eine Frage zu meinen JavaEE Beans. Ich hab 2 Beans welche in JNDI registriert werden (siehe unten) - das passt also soweit.
Wenn ich mittels @EJB dependency Injection verwende, klappts einwandfrei: 


```
@EJB(name = "jndi/TestClassBean")
public TestClass testClass;
@EJB(name = "jndi/OtherBean")
public OtherBean otherBean;
```

wenn ich @EJB mit @Resource autausche, bekomm ich eine NullPointerException: 


```
@Resource(name = "jndi/TestClassBean")
public TestClass testClass;
@Resource(name = "jndi/OtherBean")
public OtherBean otherBean;
```

Weiß jemand warum das so ist und was ich machen muss, damits auch mit @Resource klappt.
Besten Dank!
Poller


```
16:39:51,482 INFO  [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-7) JNDI bindings for session bean named OtherBean in deployment unit deployment ...

	java:global/salzburgag-javaeetest-frontend/OtherBean!at.maxqu.test.OtherBeanLocal
	java:app/...-javaeetest-frontend/OtherBean!at.maxqu.test.OtherBeanLocal
	java:module/OtherBean!at.....test.OtherBeanLocal
	java:global/...-javaeetest-frontend/OtherBean!at.....test.OtherBean
	java:app/...-javaeetest-frontend/OtherBean!at.....test.OtherBean
	java:module/OtherBean!at.maxqu.test.OtherBean

16:39:51,490 INFO  [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-7) JNDI bindings for session bean named TestClassBean in deployment unit deployment ...

	java:global/...-javaeetest-frontend/TestClassBean!at.....javaeesimpletest.TestClass
	java:app/...-javaeetest-frontend/TestClassBean!at.....javaeesimpletest.TestClass
	java:module/TestClassBean!at.maxqu.javaeesimpletest.TestClass
	java:global/...-javaeetest-frontend/TestClassBean!at.....javaeesimpletest.TestClassBean
	java:app/...-javaeetest-frontend/TestClassBean!at.....javaeesimpletest.TestClassBean
	java:module/TestClassBean!at.....javaeesimpletest.TestClassBean

16:39:52,272 INFORMATION [javax.enterprise.resource.webcontainer.jsf.config] (MS
```


----------



## JeromeC (18. Feb 2015)

Hi, lies dir das mal durch:Difference Between @Resource, @Autowired and @Inject in Spring Injection


----------

