0
我有螺紋與我的項目CDI通用DAO注入
異常問題的「主」 org.jboss.weld.exceptions.DeploymentException:WELD-001408:不滿意的依賴關係類型JpaDAO與預選賽@default 在注射點[BackedAnnotatedField] @注入私人teste.view.Principal.dao
JpaDAO(只是用於測試,沒有完全實現):
package teste.cdihibernate;
import java.util.List;
import javax.persistence.EntityManager;
public class JpaDAO<T> implements DAO<T>
{
private EntityManager em;
private final Class<T> classe;
public JpaDAO(Class<T> classe, EntityManager em)
{
this.classe = classe;
this.em = em;
}
@Override
public void save(T entity)
{
em.persist(entity);
}
@Override
public void update(T entity)
{
}
@Override
public void remove(T entity)
{
em.remove(entity);
}
@Override
public T getById(Class<T> classe, Long pk)
{
return em.find(classe, pk);
}
@Override
public List<T> getAll(Class<T> classe)
{
List<T> resultList = (List<T>) em.createQuery("select e from " + classe.getSimpleName() + " e").getResultList();
return resultList;
}
@Override
public T getByRestriction(Class<T> classe, String attribute, String filter)
{
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}
我DAOFactory
:
public class DAOFactory
{
@Inject private EntityManager em;
@SuppressWarnings({ "rawtypes", "unchecked" })
@Produces
@Dependent
public JpaDAO createJpaDAO(InjectionPoint point) throws ClassNotFoundException
{
ParameterizedType type = (ParameterizedType) point.getType();
Class classe = (Class) type.getActualTypeArguments()[0];
return new JpaDAO(classe, em);
}
}
而且我Principal.java
:
@Inject private JpaDAO<Veiculo> dao;
我在做什麼錯?
感謝您的回答,以這種方式工作:public JpaDAO createJpaDAO(InjectionPoint point)throws ClassNotFoundException –
2014-09-02 20:22:50