Nullpointerexception with CDI and JAX-RS

Asked

Viewed 94 times

2

I’m studying JAX-RS and created a simple project with the following class:

Webservice

@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 ?

1 answer

2


Friend, put more details of your Exception and also the structure of your project, is a . War ? a . Ear ?

Anyway, and most likely you must have forgotten to add the beans.xml to your project, below is 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 projects . War it should stay under the WEB-INF, for .EAR put it in the folder META-INF of the main project (Ear).

Follows a useful link of Seam on the bean.xml(In English).

If not, please specify more.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.