user297497
user297497

Reputation:

Annotations (@EJB, @Resource, ...) within a RESTful Service

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:

Thanks in advance!

br Dominik

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

Upvotes: 1

Views: 1157

Answers (4)

Jakub Marchwicki
Jakub Marchwicki

Reputation: 868

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

Upvotes: 1

navr
navr

Reputation: 72

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.

Upvotes: 0

Pascal Thivent
Pascal Thivent

Reputation: 570295

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

Upvotes: 0

PaulP1975
PaulP1975

Reputation: 528

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.

Upvotes: 0

Related Questions