我的项目有问题
线程“main”中的异常org.jboss.weld.exceptions.DeploymentException:WELD-001408:带有限定符@Default的JpaDAO类型的不满意依赖项 在注入点[BackedAnnotatedField] @Inject private 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;
我做错了什么?
答案 0 :(得分:1)
生产者方法的返回类型(JPaDAO)不能分配给所需的注射类型(JpaDAO&lt; Veiculo&gt;)。我相信你需要在你的生产者方法中添加一个类型变量。