Olá estou tentando utilizar o CDI com uma aplicação REST utilizando o RESTEasy mas estou sempre recebendo nullpointer nos objetos que estou injetando.
O objeto aplicacaoDAO está sempre vindo como nullpointer.
Minha classe inicial:
AplicacaoResource.java
package br.com.bb.apm.rest;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.inject.Named;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import br.com.bb.apm.modelo.AplicacaoDAO;
@Path("aplicacoes")
@Named
@RequestScoped
public class AplicacaoResource {
@Inject
private AplicacaoDAO aplicacaoDAO;
@GET
public String listar(){
String dao = aplicacaoDAO.teste();
return "funcionou"+dao;
}
}
AplicacaoDAO.java
package br.com.bb.apm.modelo;
public class AplicacaoDAO {
public String teste(){
return "teste dao";
}
}
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<display-name>apm-api</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<listener>
<listener-class>org.jboss.weld.environment.servlet.Listener</listener-class>
</listener>
<resource-env-ref>
<resource-env-ref-name>BeanManager</resource-env-ref-name>
<resource-env-ref-type>
javax.enterprise.inject.spi.BeanManager
</resource-env-ref-type>
</resource-env-ref>
</web-app>
context.xml
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<Resource name="BeanManager"
auth="Container"
type="javax.enterprise.inject.spi.BeanManager"
factory="org.jboss.weld.resources.ManagerObjectFactory"/>
</Context>
beans.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
version="1.2" bean-discovery-mode="all">
</beans>