JSF Deploy Exception:类型EntityManager的不满意依赖项
发布时间:2020-12-14 04:58:17 所属栏目:百科 来源:网络整理
导读:我只是按照门票怪物教程( http://www.jboss.org/jdf/examples/ticket-monster/tutorial/Introduction/)并在我的解决方案中添加了一个休息服务类. package projectFoo.rest;import java.util.List;import javax.enterprise.context.RequestScoped;import java
我只是按照门票怪物教程(
http://www.jboss.org/jdf/examples/ticket-monster/tutorial/Introduction/)并在我的解决方案中添加了一个休息服务类.
package projectFoo.rest; import java.util.List; import javax.enterprise.context.RequestScoped; import javax.inject.Inject; import javax.persistence.EntityManager; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import projectFoo.model.party; @Path("/partys") @RequestScoped public class partyService { @Inject private EntityManager em; @GET @Produces(MediaType.APPLICATION_JSON) public List<party> getAllEvents() { @SuppressWarnings("unchecked") final List<party> results = em.createQuery( "select e from party e order by e.name").getResultList(); return results; } } @Inject加下划线,返回:“没有bean有资格注入注入点[JSR-299§5.2.1]” 当我尝试部署包时,该过程将失败并返回以下消息: Unsatisfied dependencies for type [EntityManager] with qualifiers [@Default] at injection point. 我是否必须为实体管理器添加一个bean?这个怎么样?该教程没有提到这一点.实际上我在最终的ticket-monster项目中找不到任何bean的定义. 解决方法
EntityManager位于未启用CDI的工件中(JPA提供程序jar没有包含beans.xml).
您可以使用@Inject的“good old”@PersistenceContext注释insead,或者如果您想使用@Inject,您需要为EntityManager提供一个生产者,如下所示: class Resources { @SuppressWarnings("unused") @Produces @PersistenceContext private EntityManager em; ... (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |