2

I'm trying to deploy a war into a JBoss AS 7.1.1 server and the deploy fails while trying to inject the EntityManager:

17:44:48,037 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-4) MSC00001: Failed to start service jboss.deployment.unit."c3e.war".WeldService: org.jboss.msc.service.StartException in service jboss.deployment.unit."c3e.war".WeldService: org.jboss.weld.exceptions.DeploymentException: Exception List with 1 exception:
Exception 0 :
org.jboss.weld.exceptions.DeploymentException: WELD-001408 Unsatisfied dependencies for type [EntityManager] with qualifiers [@Default] at injection point [[field] @Inject xyz.beans.UploadImpl.em]
    at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:275)
    at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:244)
    at org.jboss.weld.bootstrap.Validator.validateBean(Validator.java:107)
    at org.jboss.weld.bootstrap.Validator.validateRIBean(Validator.java:127)
    at org.jboss.weld.bootstrap.Validator.validateBeans(Validator.java:346)
    at org.jboss.weld.bootstrap.Validator.validateDeployment(Validator.java:331)
    at org.jboss.weld.bootstrap.WeldBootstrap.validateBeans(WeldBootstrap.java:366)
    at org.jboss.as.weld.WeldContainer.start(WeldContainer.java:83)
    at org.jboss.as.weld.services.WeldService.start(WeldService.java:76)
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:724)

Normally I would expect that this would result from Weld being unable to find a suitable bean to be injected. However, I define a producer for the EntityManager thus:

@ApplicationScoped
public class Resources {
    @PersistenceContext(unitName="myUnit", type=PersistenceContextType.EXTENDED)
    private EntityManager entityManager;

    @Produces
    public EntityManager getEntityManager() {
        return entityManager;
    }
}

The injection-point about which it complains appears as follows:

@RequestScoped
@Named("upload")
public class UploadImpl implements Upload, Serializable {
    private static final long serialVersionUID = 1L;

    @Inject
    EntityManager em;
}

In another project exactly the same setup worked just fine. Any ideas?

4

2 回答 2

2

上面评论中回答的问题:@Produces 注释是从错误的包中导入的。谢谢你,安托万·萨博特-杜兰德!

于 2013-07-25T08:20:43.107 回答
0

只是一个长镜头,但有两种类型的注释:javax.faces.bean.ApplicationScopedjavax.enterprise.context.ApplicationScoped. 我的猜测是您的生产者使用 JSF 注释而不是 CDI 注释。

正如 CDI 规范所说:

1.2.6。与 JSF JavaServer Faces 的关系是一个 Web 层表示框架,它为图形用户界面组件提供组件模型,以及将用户界面组件绑定到可通过统一 EL 访问的对象的事件驱动交互模型。该规范允许为任何 bean 分配统一 EL 名称。 因此,JSF 应用程序可以利用本规范定义的复杂上下文和依赖注入模型。

这意味着您可以自由地将 CDI bean 注入到 JSF 托管的 bean 中,但相反的情况并非如此。容器的东西`

如果您想使用 CDI,您必须将您的注释更改为来自javax.enterprise.context包。

于 2013-07-24T17:06:37.380 回答