Inject a EJB into JAX-RS (RESTfull service)

Posted by Zeck on Stack Overflow See other posts from Stack Overflow or by Zeck
Published on 2010-06-12T07:09:14Z Indexed on 2010/06/12 7:12 UTC
Read the original article Hit count: 343

Filed under:
|
|
|
|

Hi guys,
I'm trying to inject Stateless EJB into my JAX-RS webservice via Annotations. Unfortunately the ejb is just null and I get a NullPointerException when I try to use it.

@Path("book")
public class BookResource {

    @EJB
    private BookEJB bookEJB;

    public BookResource() {
    }

    @GET
    @Produces("application/xml")
    @Path("/{bookId}")
    public Book getBookById(@PathParam("bookId") Integer id)
    {
        return bookEJB.findById(id);
    }
}

What am I wrong doing?
Here are some informations about my machine:

  • Glassfish 3.1
  • Netbeans 6.9 RC 2
  • Java EE 6

Can you guys put some working example? And thank you for every advises and examples?

© Stack Overflow or respective owner

Related posts about java

Related posts about java-ee