jar cdi ear jboss-weld

jar - Inyectando un frijol de un tarro diferente en Weld



cdi ear (3)

Tengo dos tarros A y B donde A depende de B.

Jar B tiene una sola clase:

@ApplicationScoped public class MyManagedBean { private String user; public MyManagedBean(){ //Constructor necesary for CDI } @Inject public MyManagedBean(@Named("user") String user){ this.user = user; } ... }

Jar A (más precisamente, un jar EJB) tiene un bean:

@ApplicationScoped public class AnotherManagedBean { public AnotherManagedBean(){ //Constructor necesary for CDI } @Inject public AnotherManagedBean(MyManagedBean bean){ ... } }

Y un bean de configuración con un método @Produces:

@ApplicationScoped public class ConfigurationBean { public ConfigurationBean(){ //Constructor necesary for CDI } @Produces @Named("user") public String getUser(){ return "myUser"; } }

Sin embargo, cuando implemento un EAR con ambos Jars obtengo esta excepción:

SEVERE: Exception while loading the app : WELD-001408 Unsatisfied dependencies for type [String] with qualifiers [@Named] at injection point [[parameter 1] of [constructor] @Inject public com.example.MyManagedBean(String)] org.jboss.weld.exceptions.DeploymentException: WELD-001408 Unsatisfied dependencies for type [String] with qualifiers [@Named] at injection point [[parameter 1] of [constructor] @Inject public com.example.MyManagedBean(String)] at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:270) at org.jboss.weld.bootstrap.Validator.validateBean(Validator.java:106) at org.jboss.weld.bootstrap.Validator.validateRIBean(Validator.java:129) at org.jboss.weld.bootstrap.Validator.validateBeans(Validator.java:351) at org.jboss.weld.bootstrap.Validator.validateDeployment(Validator.java:336) at org.jboss.weld.bootstrap.WeldBootstrap.validateBeans(WeldBootstrap.java:396) at org.glassfish.weld.WeldDeployer.event(WeldDeployer.java:190) at org.glassfish.kernel.event.EventsImpl.send(EventsImpl.java:128) at org.glassfish.internal.data.ApplicationInfo.start(ApplicationInfo.java:306) at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:462) at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:240) at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:382) at com.sun.enterprise.v3.admin.CommandRunnerImpl$1.execute(CommandRunnerImpl.java:355) at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:370) at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1064) at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1200(CommandRunnerImpl.java:96) at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1244) at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1232) at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:459) at com.sun.enterprise.v3.admin.AdminAdapter.service(AdminAdapter.java:209) at com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:168) at com.sun.enterprise.v3.server.HK2Dispatcher.dispath(HK2Dispatcher.java:117) at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:238) at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:828) at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:725) at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1019) at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225) at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137) at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104) at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90) at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79) at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54) at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59) at com.sun.grizzly.ContextTask.run(ContextTask.java:71) at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532) at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513) at java.lang.Thread.run(Thread.java:662)

¿Alguna idea?

Gracias


Asegúrese de que ambos archivos sean "archivos de bean", es decir, tienen META-INF/beans.xml


Estaba teniendo exactamente el mismo problema y pude resolverlo pero uso una oreja para combinar los frascos.

Diseño del oído

project.ear |-- META-INF | |-- MANIFEST.MF | |-- application.xml* |-- one.jar (bean archive) | |-- META-INF | | |-- beans.xml | |-- <code> |-- two.jar (ejb)

  • application.xml

<application> <display-name>test-application</display-name> <module> <ejb>two.jar</ejb> </module> <module> <java>one.jar</java> </module> </application>

Haciendo eso, hizo que one.jar estuviera disponible para two.jar en el contenedor.

-kurt


Una cosa, tiene que crear una anotación de Qulifier para especificar exactamente qué debe inyectarse.

@Qualifier @Retention(RUNTIME) @Target({METHOD, FIELD, PARAMETER, TYPE}) public @interface UserConfiguration { }

y entonces..

@Produces @UserConfiguration @Named("user") public String getUser(){ return "myUser"; }

para inyección ..

@Inject public MyManagedBean(@UserConfiguration String user){ this.user = user; }

vea también http://docs.jboss.org/weld/reference/1.1.0.Final/en-US/html_single/#d0e1355