Personally I'm getting an exception when injecting my DAO. Unsatisfied dependencies for type [ProjectDao]
No bean matches the injection point.
ProjectDao.class
public class ProjectDao<T> implements Serializable{
private final Class<T> entityClass;
@PersistenceContext(unitName = "ProjectPU")
private EntityManager em;
public ProjectDao(Class<T> entityClass) {
this.entityClass = entityClass;
}
public void create(T entity) {
em.persist(entity);
}
public void edit(T entity) {
em.merge(entity);
}
public void remove(T entity) {
em.remove(em.merge(entity));
}
public T find(Object id) {
return em.find(entityClass, id);
}
public List listaTodos() {
CriteriaQuery query = em.getCriteriaBuilder().createQuery(entityClass);
query.from(entityClass);
return em.createQuery(query).getResultList();
}
UserService.java
@RequestScoped
@Path("usuario")
@Produces(MediaType.APPLICATION_JSON)
public class UsuarioService {
@Inject
private ProjectDao<Usuario> dao;
@POST
@Consumes({"application/json"})
public void created(Usuario entity) {
dao.create(entity);
}
}