0

I want to Inject a EJB in a jax-rs class. I get always a NullPointerException. Can anybody help me. The Jax-RS class has following construct:

@Stateless
@Path("uom")
public class RestUOM {

    @EJB UOMService memoryService;

    @GET
    @Path("memory/{hostId}")
    @Produces(MediaType.TEXT_XML)
    public String checkMemory(@PathParam("hostId") Integer hostId){
        Memory memory = this.memoryService.getMemory(hostId); //this.memoryService is null
        StringWriter sw = new StringWriter();
        JAXB.marshal(memory, sw);
        String result = sw.toString();
        return result;
    }

Why is the local variable memoryService always null?

TFrost
  • 769
  • 2
  • 12
  • 31
Florian D
  • 56
  • 1
  • 9
  • What kind of interface does your bean have (local, remove, none) and where is the ejb located. Also what version of Java EE are you using? – raphaëλ Aug 17 '15 at 12:30
  • The bean is a localbean. the UOMService class is in another package as the RestUOM class. Java EE Version: 1.7 – Florian D Aug 17 '15 at 12:33
  • Make sure that you're not deploying Jersey or RestEASY jars (or any other JAX-RS implementation) with your application – Steve C Aug 17 '15 at 12:48
  • Thank you very much for your help. I deployed a unused jersey jar. I wanted to upvote your awnser but i clicked it twice, sry. – Florian D Aug 17 '15 at 13:09
  • possible duplicate of [Inject an EJB into JAX-RS (RESTful service)](http://stackoverflow.com/questions/3027834/inject-an-ejb-into-jax-rs-restful-service) – V G Aug 17 '15 at 14:26

0 Answers0