jacktrades
jacktrades

Reputation: 7392

Access EJB from JAX-RS

While Developing a Java EE Web app, I would like to know simple ways to access an stateless EJB object through Rest.

This project needs no Dynamic Web from Java, as Client side is fully javascript deployed, so communication is done only with Ajax calls.

As I've read one way would be to create 2 EJB one for functionality other to represent Web Service.

Is there a way to avoid the Web Service part? (avoid completely the WAR) Maybe with DI?

Java EE 6, EJB 3.1, Eclipse desired. I also believe the right application server would be Glassfish instead of Jboss, due to it's compatibility with EJB 3.0

No interesting in using JAX-WS

Upvotes: 1

Views: 1077

Answers (2)

Csaba
Csaba

Reputation: 949

With EJB 3.1 you can actually publish a session bean as a JAX-RS web service, if you package your (properly annotated) session bean inside a WAR.

So, the simplest solution I can think of would be to create a WAR (a dynamic web app if you're using Eclipse) and create a JAX-RS annotated stateless session bean inside the web app. You don't need any EJB projects at all.

Upvotes: 1

Will Hartung
Will Hartung

Reputation: 118593

Not really. In Java EE 6 you can directly publish a Session Bean as a JAX-WS web service, but not as a JAX-RS web service. You're pretty much stuck with creating a WAR that hosts that JAX-RS services that front the EJBs themselves.

Upvotes: 1

Related Questions