I'm having trouble injecting dao bean declared on a lib jar. So I have a jar (mine) with a persistence context, entities and daos. Here is a dao example :
@Stateless
public class SomeDao {
@PersistenceContext
private EntityManager em;
...
}
Now I want to use this dao on my main application.
A jax-rs use case :
@Path("rs")
public class WebService{
@Inject
private SomeDao dao;
@POST
public Response doPost(){
//dao is injected but nullpointer thrown on EntityManager
dao.doSomething();
}
...
}
There is a beans.xml in both project (under META-INF/ for lib, WEB-INF/ for the web application). like this one :
<?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>
------------- Edit ------------
I've just found out if I remove the @Stateless annotation and the producer it works. So the problem is in fact : how to inject with CDI an EJB declared on an lib jar.