【问题标题】:JSF Deploy Exception: Unsatisfied dependencies for type EntityManagerJSF 部署异常:EntityManager 类型的依赖关系不满足
【发布时间】:2013-03-03 00:51:06
【问题描述】:

我刚刚按照ticket-monster 教程(http://www.jboss.org/jdf/examples/ticket-monster/tutorial/Introduction/) 并在我的解决方案中添加了一个rest-service 类。

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的定义。

【问题讨论】:

    标签: jsf jakarta-ee maven jboss inject


    【解决方案1】:

    EntityManager 位于未启用 CDI 的工件中(JPA 提供程序 jar 不包含 beans.xml)。

    您可以在@Inject 中使用“good old”@PersistenceContext 注释,或者如果您想使用@Inject,您需要像这样为 EntityManager 提供生产者:

    class Resources {
       @SuppressWarnings("unused")
       @Produces
       @PersistenceContext
       private EntityManager em;
    ...
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-01-21
      • 1970-01-01
      • 2018-12-19
      • 2021-04-08
      • 2015-10-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多