views:

231

answers:

3

Hi!

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.

A: 

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.

PaulP1975
doh... sorry... i should read more closely. i just noticed the "remote EJB-project"... my apologies.
PaulP1975
A: 

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).

Pascal Thivent
Ok, so I'll try JBoss 5. I already perform a lookup as workaround. Thank you!
Dominik
@Dominik You're welcome.
Pascal Thivent
A: 

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.

navr