문제

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?

도움이 되었습니까?

해결책

Question answered in a comment above: the @Produces annotation was imported from the wrong package. Thank you, Antoine Sabot-Durand!

다른 팁

Just a long shot, but there are two types of annotations: javax.faces.bean.ApplicationScoped and javax.enterprise.context.ApplicationScoped. My guess is that your producer is annotated with the JSF annotation instead of the CDI one.

As the CDI spec says:

1.2.6. Relationship to JSF JavaServer Faces is a web-tier presentation framework that provides a component model for graphical user interface com- ponents and an event-driven interaction model that binds user interface components to objects accessible via Unified EL. This specification allows any bean to be assigned a Unified EL name. Thus, a JSF application may take advantage of the sophisticated context and dependency injection model defined by this specification.

This means you're free to inject CDI beans to the JSF managed beans, however the opposite is not true. The container things that the `

If you want to use CDI you have to chage your annotations to come from the javax.enterprise.context package.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top