微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

JSF Deploy Exception:类型EntityManager的不满意依赖项

我只是按照门票怪物教程( 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;
...

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐