Question

I have a project with some web artifacts (.war) and I'm facing problems to Inject simple POJOs. The following code represents the simplest working case:

.war (WAR1)

public class MyManagedBean {
    @Inject
    private MyPojo myPojo;   
}

POJO in .war (WAR1)

public class MyPojo {
    public void doSomething() {}
}

The problem occurs when I add one more web artifact (.war --> WAR2) with the same POJO (MyPojo) packaged. Semantically I want my POJO in each web artifact, not an external archive (.jar). Basically the newest added component (WAR2) is identical to WAR1, i.e., it simulates as if it existed a multimodule project. At runtime, container raises the following error when trying to use a module:

Caused by: org.jboss.weld.exceptions.DeploymentException: WELD-001408 Unsatisfied dependencies for type [MyPojo] with qualifiers [@Default] at injection point [[field] @Inject private com.projectx.MyManagedBean.myPojo]
at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:270) [:6.1.0.Final]
at org.jboss.weld.bootstrap.Validator.validateInjectionTarget(Validator.java:299) [:6.1.0.Final]
at org.jboss.weld.manager.InjectionTargetValidator.addInjectionTarget(InjectionTargetValidator.java:34) [:6.1.0.Final]
at org.jboss.weld.manager.BeanManagerImpl.createInjectionTarget(BeanManagerImpl.java:1055) [:6.1.0.Final]
at org.jboss.weld.manager.BeanManagerImpl.fireProcessInjectionTarget(BeanManagerImpl.java:1249) [:6.1.0.Final]
at org.jboss.weld.integration.injection.Jsr299SimpleNonContextualInjector.inject(Jsr299SimpleNonContextualInjector.java:66) [:6.1.0.Final]
at org.jboss.injection.manager.core.DefaultInjectionContext.proceed(DefaultInjectionContext.java:58) [:1.0.0-alpha-7]
at org.jboss.injection.manager.core.DefaultInjectionManager.inject(DefaultInjectionManager.java:58) [:1.0.0-alpha-7]
at org.jboss.injection.manager.core.DefaultInjectionManager.inject(DefaultInjectionManager.java:64) [:1.0.0-alpha-7]
at org.jboss.web.tomcat.service.TomcatInjectionContainer.processInjectors(TomcatInjectionContainer.java:410) [:6.1.0.Final]
at org.jboss.web.jsf.integration.injection.JBossDelegatingInjectionProvider.inject(JBossDelegatingInjectionProvider.java:77) [:1.0.3]
... 66 more

Some scenarios details:

  1. If I remove WAR2, the injection made by WAR1 starts to work.
  2. Both of artifacts (WAR1 and WAR2) have the same POJOs and beans.xml (/WEB-INF).

Is there any point am I missing? All I need is the possibility to inject a class, like a "*.Helper" for example. As I know, CDI allows to Inject even primitive types.

  • JDK 1.7
  • JBoss 6.1.0
  • Weld 1.1.Beta2
Was it helpful?

Solution

Unfortunately using JBoss 6.1.0 AS packaged with Weld 1.1.Beta2 really doesn't work. As a test, tried the same implementation with Glassfish 3.1.2 and CDI injection worked like a charm.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top