NullPointerException with CDI and JAX-RS

2

I am studying JAX-R S and created a simple project with the following class:

Webservice Code

@Path("generic")
public class GenericResource {

    @Inject
    private MeuServico servico;

    @GET
    @Produces("text/plain")
    public String getText() {
        return servico.getText();
    }
}

Service

@Stateless
public class MeuServico {

    public String getTExtt() {
        return "Teste";
    }
}

I'm getting NullPointerException on the line of return servico.getText(); Does anyone know what it can be?

    
asked by anonymous 26.06.2014 / 01:30

1 answer

2

Friend, put more details of your exception and also the structure of your project, is a .war? an .ear?

Anyway, and most likely you should have forgotten to add beans.xml to your project, here's an example:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://java.sun.com/xml/ns/javaee"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="
      http://java.sun.com/xml/ns/javaee 
      http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
</beans> 

For .war projects it should be under WEB-INF , for .EAR put it in the META-INF folder of the main project (ear).

Follow Seam's useful link on bean.xml .

If not, please specify more.

    
26.06.2014 / 01:36