1
votes

I'm trying to inject a EJB within my RESTful Service (RESTEasy) via Annotations.

public class MyServelet implements MyServeletInterface {

...

@EJB

MyBean mybean;

...

}

Unfortunately there is no compilation or AS error, the variable "mybean" is just null and I get a NullPointerException when I try to use it.

What I'm doing wrong?

Here are some side-informations about my architecture:

  • JBoss 4.2.2.GA
  • Java version: 1.5.0_17
  • local MDB-Project
  • remote EJB-Project
  • WAR Project with the RESTful Service which uses the remote EJB and sends messages to the local MDB-Project

Thanks in advance!

br Dominik

p.s: everything is working fine when I use normal context lookup.

4

4 Answers

1
votes

I had a similar problem (though without @Remote beans). The way it worked for me - sample application is here: https://github.com/kubamarchwicki/rest-app/ (this works: https://github.com/kubamarchwicki/rest-app/blob/master/service-webapp/src/main/webapp/WEB-INF/web.xml#L9)

The crack with context lookup is that the name changes with a change of the ear name. If you fancy things like versions, it makes the whole thing hard to trace or forces you to hardcode ear name somewhere in the code.

Just a few cents to an old discussion ;-)

0
votes

This is not exactly my forte, so maybe I am way off... but, can you do EJB stuff in a WAR? I was under the impression you needed to do EJB work in an EAR.

0
votes

JBoss 4.2.2.GA is not a fully compliant Java EE 5 server, it does not support EJB references injection in servlets or application clients, only in the EJB layer. Use JBoss 5 for that (or perform a lookup).

0
votes

JBoss 4.2.2.GA supports only Servlet 2.4. There is no support of DI on Servlet 2.4. Hence you always get 'null' for myBean variable. As suggested, please migrate to JBoss 5.0 which supports Servlet 2.5 which makes use of Java 5 features like annotations.