Return-Path: X-Original-To: apmail-openwebbeans-user-archive@www.apache.org Delivered-To: apmail-openwebbeans-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 2715E1140B for ; Thu, 12 Jun 2014 18:48:41 +0000 (UTC) Received: (qmail 71727 invoked by uid 500); 12 Jun 2014 18:48:41 -0000 Delivered-To: apmail-openwebbeans-user-archive@openwebbeans.apache.org Received: (qmail 71697 invoked by uid 500); 12 Jun 2014 18:48:40 -0000 Mailing-List: contact user-help@openwebbeans.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@openwebbeans.apache.org Delivered-To: mailing list user@openwebbeans.apache.org Received: (qmail 71689 invoked by uid 99); 12 Jun 2014 18:48:40 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 12 Jun 2014 18:48:40 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of fop.net@gmail.com designates 209.85.213.54 as permitted sender) Received: from [209.85.213.54] (HELO mail-yh0-f54.google.com) (209.85.213.54) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 12 Jun 2014 18:48:36 +0000 Received: by mail-yh0-f54.google.com with SMTP id i57so1304775yha.41 for ; Thu, 12 Jun 2014 11:48:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=WChCgIUy2ix4OvF0xiFhx1/xAzpuPNNpkLbQG/unh2g=; b=unXn7GM9ara2mXkVYfASsZrvGhX0SR5eENhTlxwbAHGZdBFEpevKOy6UdEsIBfHL/x a+b+9PoJGXGwT44FIGG53ypzxjYGAM+P7+uo5qlsznPkoo+DSuuTNMoRzL6Ehb4vPwsa Bj3hsbcecVD1ganegYL+3X1JH1raUH/15pR5ThZ96fyfFE+oeumypWXYn7sSrPW+bGbh doac7ChY7kQMJsKqcSvj+r/b5SLzy9FXQ8nBZeLkCsYywY53Lb7T1FfxhHbGu36IqxTB /FQ3qnYV6hT852ORZ/itfFjwghUicSmsO3t0jzqNbq3VS+Q7xXBEQshtpSHz3ypNjFMG 3bQA== X-Received: by 10.236.156.170 with SMTP id m30mr17995540yhk.60.1402598895160; Thu, 12 Jun 2014 11:48:15 -0700 (PDT) MIME-Version: 1.0 Received: by 10.170.40.196 with HTTP; Thu, 12 Jun 2014 11:47:55 -0700 (PDT) In-Reply-To: <1402595575.48883.YahooMailNeo@web28906.mail.ir2.yahoo.com> References: <1402595575.48883.YahooMailNeo@web28906.mail.ir2.yahoo.com> From: Felipe Pina Date: Thu, 12 Jun 2014 15:47:55 -0300 Message-ID: Subject: Re: Lookup bean using beanManager returning null To: user@openwebbeans.apache.org, Mark Struberg Content-Type: multipart/alternative; boundary=20cf303a2f81e8943204fba80062 X-Virus-Checked: Checked by ClamAV on apache.org --20cf303a2f81e8943204fba80062 Content-Type: text/plain; charset=UTF-8 Thank you Mark for attention, unfortunately do not have my code online. But i think that i put all necessary informations to your diagnostic, including my dependencies . i hope it is clear, and I am available to answer any questions you may have Regards *Felipe* *---------------------------------------------------------------------------------------------------------------------------------- package* *WAR* * |- WebProject* * |- com.company.bean.JSFBean.PedidosMBean* * |- BusinessProject* * |- com.company.bean.Permissao* * |- com.company.factory.BeanFactory* * |- com.company.command.Command* *---------------------------------------------------------------------------------------------------------------------------------- JSF bean* */* CDI Scope & bean */@javax.inject.Named("pedidoMBean")@javax.enterprise.context.SessionScoped public class PedidoMBean { ....}----------------------------------------------------------------------------------------------------------------------------------Binding @Qualifier @Retention(RUNTIME) @Target({TYPE, METHOD, FIELD, PARAMETER}) public @interface BusinessBean {}---------------------------------------------------------------------------------------------------------------------------------- BeanFactory * *public class BeanFactory { static BeanManager getBeanManager() { InitialContext context; Object result; try { context = new InitialContext(); result = context.lookup("java:comp/env/BeanManager"); //lookup in Tomcat } catch (NamingException e) { try { context = new InitialContext(); result = context.lookup("java:comp/BeanManager"); //lookup in JBossAS } catch (NamingException ex) { throw new RuntimeException("BeanManager could not be found in JNDI", e); } } return (BeanManager) result; } @SuppressWarnings("unchecked") public static T getContextualInstance(final Class type) { BeanManager manager = getBeanManager(); T result = null; @SuppressWarnings("serial") Annotation[] annotations = { new AnnotationLiteral() {} }; Set> beans = manager.getBeans(type, annotations); beans = manager.getBeans(type); -> isEmty beans = manager.getBeans("teste"); -> isEmty* * Bean bean = (Bean) manager.resolve(beans); -> isEmty * * if (bean != null) { CreationalContext context = manager.createCreationalContext(bean); if (context != null) { result = (T) manager.getReference(bean, type, context); } } return result; }} ---------------------------------------------------------------------------------------------------------------------------------- Business Bean* *@javax.enterprise.context.RequestScoped @BusinessBean@Named(value="teste")public class Permissao extends NegocioBase { .... public Permissao() {} * *}---------------------------------------------------------------------------------------------------------------------------------- Caller Class * *public class Command {* * public void invoke() {* Permissao bo = BeanFactory.getContextualInstance(Permissao.class) ; bo -> is null * }* *}* *---------------------------------------------------------------------------------------------------------------------------------- * *Master **pom.xml* * 4.0.0 com.company builder 0.2.1-SNAPSHOT Master pom ../BusinessProject ../WebProject * * 1.2.1 * org.apache.geronimo.specs geronimo-atinject_1.0_spec 1.0 compile org.apache.geronimo.specs geronimo-jcdi_1.0_spec 1.0 compile org.apache.geronimo.specs geronimo-interceptor_1.1_spec 1.0 compile org.apache.openwebbeans openwebbeans-impl ${openwebbeans.version} runtime org.apache.openwebbeans openwebbeans-web ${openwebbeans.version} runtime org.apache.openwebbeans openwebbeans-spi ${openwebbeans.version} runtime * * org.apache.geronimo.bundles scannotation 1.0.2_1 *---------------------------------------------------------------------------------------------------------------------------------- web Project* 4.0.0 *com.company* builder 0.2.1-SNAPSHOT ../Master/pom.xml war WebProject *WebProject* *com.company* BusinessProject ${project.version} ** *---------------------------------------------------------------------------------------------------------------------------------- Business Project* 4.0.0 *com.company* builder 0.2.1-SNAPSHOT ../Master/pom.xml jar *BusinessProject* BusinessProject 2014-06-12 14:52 GMT-03:00 Mark Struberg : > Hi Felipe! > > Let me first ask you what you intend to do. I like to learn about your use > case and then we should be able to help you. > > Your sample shows a class (Permissao) which has no qualifier annotations > at all. > > But your sample also shows a Qualifier @BusinessBean. Where do you use it? > Do you get a BeanManager at all? > > Do you have your sample online somewhere? Maybe on github? > That would really make it easier for us to help you. > > LIeGrue, > strub > > > > On Thursday, 12 June 2014, 19:11, Felipe Pina wrote: > > > > I haved changed my method according to your reference > http://deltaspike.apache.org/core.html#beanprovider > > but still no success :( > > @SuppressWarnings("unchecked") > public static T getContextualInstance(final Class type) { > BeanManager manager = getBeanManager(); > T result = null; > > @SuppressWarnings("serial") > Annotation[] annotations = { new AnnotationLiteral() {} }; > > Set> beans = manager.getBeans(type, annotations); -> empty > beans = manager.getBeans(type); -> empty > beans = manager.getBeans("teste"); -> empty > Bean bean = (Bean) manager.resolve(beans); > if (bean != null) { > CreationalContext context = > manager.createCreationalContext(bean); > if (context != null) { > result = (T) manager.getReference(bean, type, context); > } > } > return result; > } > > *My dependencies * > > > 1.2.1 > > > > org.apache.geronimo.specs > geronimo-atinject_1.0_spec > 1.0 > compile > > > > org.apache.geronimo.specs > geronimo-jcdi_1.0_spec > 1.0 > compile > > > > org.apache.geronimo.specs > geronimo-interceptor_1.1_spec > 1.0 > compile > > > > org.apache.openwebbeans > openwebbeans-impl > ${openwebbeans.version} > runtime > > > > org.apache.openwebbeans > openwebbeans-web > ${openwebbeans.version} > runtime > > > > > org.apache.openwebbeans > openwebbeans-spi > ${openwebbeans.version} > runtime > > > > > > 2014-06-12 10:03 GMT-03:00 Thomas Andraschko > : > > Maybe you miss the beans.xml in your jar but the way how you call > #getBeans with an qualifier is wrong. > > > 2014-06-12 14:55 GMT+02:00 Felipe Pina : > > Take a look to my tests. The focus is not how am i passing as parameter > annotation, because the lookup by name works to bean inside WebProject but > not works to bean inside BusinessProject > > I have tested using three ways of lookup the bean, and both of bean are > annotated similarly, but the webproject bean works and the BussinessProject > bean do not works (jar package). > > Set> beans = manager.getBeans(type, > type.getAnnotation(BusinessBean.class)); > Set> beans = manager.getBeans(type); > Set> beans = manager.getBeans("teste"); > > > > > 2014-06-12 9:34 GMT-03:00 Thomas Andraschko : > > You need to a pass a AnnotationLiteral instance instead of > "type.getAnnotation(yourAnnotation.class)" > Here it's explained how to create one and use one: > http://deltaspike.apache.org/core.html#beanprovider > > > > 2014-06-12 14:26 GMT+02:00 Gerhard Petracek : > > @felipe: > we won't respond something different (see [1]), if you keep the wrong code. > the one case you mentioned just works, because #getAnnotation returns null. > > regards, > gerhard > > [1] http://s.apache.org/oDb > > > > 2014-06-12 14:16 GMT+02:00 Thomas Andraschko > : > > Have a look at the bean manager java doc -> > > *getBeans > *(java.lang.reflect.Type beanType, > java.lang.annotation.Annotation... qualifiers) > > RequestScoped isn't a CDI qualifier! ;) > > > 2014-06-12 14:03 GMT+02:00 Felipe Pina : > > Questions > > > 1. Is there any schema that uses in the beans.xml file that configures > the engine to evaluate candidates beans through a package path? > 2. the fact that the bean be packaged inside a jar which in turn, > within a war, is impediment to the proper functioning of the injection of > bean? > > > > *Tests* > > 1. lookup bean from string value > > > 1. lookup "teste" -> works fine > 2. lookup "perm" -> *fail returning null* > > > - lookup bean from type > > > 1. lookup using Permissao.class -> * fail returning null* > > > > *Project Structure* > > *WAR* > * |- WebProject* > * |- com.company.bean.JSFBean -> **@Named(value="teste")* > * |- BusinessProject* > * |- com.company.bean.Permissao -> * > *@Named(value="perm") @BusinessBean* > > *My Qualifier* > > @Qualifier > @Retention(RUNTIME) > @Target({TYPE, METHOD, FIELD, PARAMETER}) > public @interface BusinessBean { > > } > > *My bean.* > > @javax.enterprise.context.RequestScoped > @javax.enterprise.inject.Default > public class Permissao extends NegocioBase { > .... > } > > > *context.xml* > auth="Container" > type="javax.enterprise.inject.spi.BeanManager" > factory="org.apache.webbeans.container.ManagerObjectFactory"/> > > > *web.xml* > > > > Object factory for the CDI Bean Manager > BeanManager > > javax.enterprise.inject.spi.BeanManager > > > *BeanFactory* > > public class BeanFactory { > static BeanManager getBeanManager() { > InitialContext context; > Object result; > try { > context = new InitialContext(); > result = context.lookup("java:comp/env/BeanManager"); //lookup in > Tomcat > } catch (NamingException e) { > try { > context = new InitialContext(); > result = context.lookup("java:comp/BeanManager"); //lookup > in JBossAS > } catch (NamingException ex) { > throw new RuntimeException("BeanManager could not be found > in JNDI", e); > } > } > return (BeanManager) result; > } > @SuppressWarnings("unchecked") > public static T getContextualInstance(final Class type) { > BeanManager manager = getBeanManager(); > T result = null; > *Set> beans = manager.getBeans(type, > type.getAnnotation(RequestScoped.class));* > *---- > why variable beans isEmpty !!!* > Bean bean = (Bean) manager.resolve(beans); > if (bean != null) { > CreationalContext context = > manager.createCreationalContext(bean); > if (context != null) { > result = (T) manager.getReference(bean, type, context); > } > } > return result; > } > } > > -- > Atenciosamente, > Felipe Pina > > > > > > > > -- > Atenciosamente, > Felipe Pina > > > > > > -- > Atenciosamente, > Felipe Pina > > > -- Atenciosamente, Felipe Pina --20cf303a2f81e8943204fba80062 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable

Thank you Mark for attention, unfo= rtunately do not have my code online.

But i think that i put all necessary i= nformations to your diagnostic, including my dependencies .

i hope = it is clear, and I am available to answer any questions you may have=

Regards
Felipe

----------------------------= ---------------------------------------------------------------------------= --------------------------- package=

WAR
=C2=A0 |- WebProject
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 |- com.compan= y.bean.JSFBean.PedidosMBean
=C2=A0 |- =C2=A0BusinessProject
=C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0|- com.company.bean.Permissao
<= /div>
=C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0|- com.company.factory.BeanFactory=
=C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0|- com.company.command.Command
=
----------------------------= ---------------------------------------------------------------------------= --------------------------- JSF bean

/* CDI Scope & bean */
@java= x.inject.Named("pedidoMBean")
@javax.enterprise.context= .SessionScoped
public class PedidoMBean = =C2=A0{

=C2=A0 =C2=A0....
}
------------------------------------------------------------= ----------------------------------------------------------------------Bindi= ng

@Qualifier=C2=A0
@Retention= (RUNTIME)=C2=A0
@Target({TYPE, METHOD, FIELD, PARAMETER})
public @interface BusinessBean {

}
----------------------------------------= ---------------------------------------------------------------------------= --------------- BeanFactory

public class BeanFactory {
static BeanManager getBeanManager() {
=C2=A0 =C2=A0Initi= alContext context;
=C2=A0 =C2=A0Object result;
=C2=A0 =C2=A0try {
=C2=A0 =C2=A0 =C2= =A0 =C2=A0context =3D new InitialContext();
=C2=A0 =C2=A0 =C2=A0 =C2=A0result =3D contex= t.lookup("java:comp/env/BeanManager"); //lookup in Tomcat
=C2=A0 =C2=A0} cat= ch (NamingException e) {
=C2=A0 =C2=A0 =C2=A0 =C2=A0try {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0co= ntext =3D new InitialContext();
=C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0result =3D context.lookup("java:comp/BeanManag= er"); //lookup in JBossAS
=C2=A0 =C2=A0 =C2=A0 =C2=A0} catch (NamingException ex) {=
=C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0throw new RuntimeException("BeanManager could = not be found in JNDI", e);
=C2=A0 =C2=A0 =C2=A0 =C2=A0}
=C2=A0 =C2=A0}
=C2=A0 =C2=A0return (= BeanManager) result;
= }
@SuppressWarnings(&= quot;unchecked")
= public static <T> T getContextualInstance(final Class<T>= ; type) {
BeanManager manage= r =3D getBeanManager();
=C2=A0 =C2=A0T result =3D null;
=C2=A0 =C2=A0
=C2=A0 =C2=A0@Supp= ressWarnings("serial")
Annotation[] annotations =3D { new AnnotationLiteral<= ;BusinessBean>() {} };
=C2=A0 =C2=A0 =C2=A0 =C2=A0=C2=A0
Set<Bean<?>> beans =3D manager.getBea= ns(type, annotations);
beans =3D manager.getBeans(type); =C2=A0 = -> isEmty
beans =3D manager.= getBeans("teste");=C2=A0-> isEmty
Bean<T> bean =3D (Bean<= ;T>) manager.resolve(beans);=C2=A0-> isEmt= y
=C2=A0 =C2=A0if (bean !=3D null) {
= =C2=A0 =C2=A0 =C2=A0 = =C2=A0CreationalContext<T> context =3D manager.createCreationalContex= t(bean);
=C2=A0 =C2=A0 =C2= =A0 =C2=A0if (context !=3D null) {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0result =3D (= T) manager.getReference(bean, type, context);
=C2=A0 =C2=A0 =C2=A0 =C2=A0}
=C2=A0 =C2=A0}
=C2=A0 =C2=A0ret= urn result;
}<= /div>
}

----------------------------------------------------------------------= ------------------------------------------------------------ Business Bean<= /div>
@javax.= enterprise.context.RequestScoped
@BusinessBean

=
@Named(value=3D"teste")
public class Permiss= ao extends NegocioBase<PermissaoDTO> =C2=A0{
=C2=A0....
=C2=A0 =C2=A0 =C2=A0 public=C2=A0Permissao() {}
}

<= div>--------------------------------------------------------------------= -------------------------------------------------------------- =C2=A0 Calle= r Class

pu= blic class Command {
=
=C2=A0 pub= lic void invoke() {
=C2=A0 =C2=A0 =C2=A0 =C2=A0Permissao bo =3D BeanFactory.getContextualI= nstance(Permissao.class) ;=C2=A0
=C2=A0 =C2=A0 =C2=A0 =C2=A0bo -&= gt; is null=C2=A0
=C2= =A0 }
}



-----------------------------------------------------= ---------------------------------------------------------------------------= --=C2=A0Master=C2=A0pom.xml

=C2=A0 <modelVersion>4.0.0</modelVersion>
=C2=A0 <groupId>com.company<= /groupId>
=C2=A0 <artifactId>builder</artifactI= d>
=C2=A0 <version>0.2.1-SNAPSHOT</version>
=C2=A0= <name>Master</name>
=C2=A0 <packaging>po= m</packaging>
=C2=A0=C2=A0
=C2=A0 <= ;modules>
=C2=A0 =C2=A0 <module>../B= usinessProject</module>

=C2=A0 =C2=A0 &= lt;module>../WebProject</module>
=C2=A0 </modul= es>

=C2=A0 <properties>
=C2=A0 =C2=A0 <openwebbeans.version>1.2.1</openwebbe= ans.version>

=C2=A0 </properties>
<= div>
<!-- =C2=A0******= ********************************************** OpenWebBeans Specifications = -->
=C2=A0 =C2=A0 =C2=A0 =C2=A0 <!-- JSR-330= -->
=C2=A0 =C2=A0 =C2=A0 =C2=A0 &l= t;dependency>
=C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 <groupId>org.apache.geronimo.specs</groupId&g= t;
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 &= lt;artifactId>geronimo-atinject_1.0_spec</artifactId>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 <vers= ion>1.0</version>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 <scope>compile</scope>= ;
=C2=A0 =C2=A0 =C2=A0 =C2=A0 </dep= endency>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 <!-- JSR-299 =C2=A0-->
=C2=A0 =C2=A0 =C2=A0 =C2=A0 <dependency>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 <g= roupId>org.apache.geronimo.specs</groupId>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 <artifactId>geronimo-jcdi_1= .0_spec</artifactId>
=C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 <version>1.0</version>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 <= scope>compile</scope>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 </dependency= >

=C2=A0 =C2=A0 =C2=A0 =C2=A0 <dependency>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 <groupId>= org.apache.geronimo.specs</groupId>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 &= lt;artifactId>geronimo-interceptor_1.1_spec</artifactId>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 <v= ersion>1.0</version>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 <scope>compile</scope>= ;
=C2=A0 =C2=A0 =C2=A0 =C2=A0 </dep= endency>
=C2=A0 =C2=A0 =C2=A0 =C2=A0=C2=A0
=C2=A0 =C2=A0 =C2=A0 =C2=A0 <dependency>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 <groupId>org.apach= e.openwebbeans</groupId>
=C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 <artifactId>openwebbeans-impl</= artifactId>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 &= lt;version>${openwebbeans.version}</version>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 <scope>runt= ime</scope>
=C2=A0 =C2=A0 =C2=A0= =C2=A0 </dependency>

= =C2=A0 =C2=A0 =C2=A0 =C2=A0 <dependency>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 <groupId>org.apach= e.openwebbeans</groupId>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 <artifactId>openwebbeans-we= b</artifactId>
=C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 <version>${openwebbeans.version}</version= >
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 <scope>runtime</scope>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 </dependency= >
=C2=A0 =C2=A0 =C2=A0 =C2=A0=C2=A0=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0<= ;!-- SPI (Service Provider Interface). -->
=C2=A0 =C2=A0 <depen= dency>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 <groupId>org.apache.openwebbeans</groupId>
<= div style=3D"font-weight:bold">=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 &l= t;artifactId>openwebbeans-spi</artifactId>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 &= lt;version>${openwebbeans.version}</version>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 <scope>runt= ime</scope>
=C2=A0 =C2=A0 =C2=A0= =C2=A0 </dependency> =C2=A0 =C2=A0 =C2=A0 =C2=A0
=C2=A0 =C2=A0 =C2=A0 =C2=A0=C2=A0
=C2=A0 =C2=A0 =C2=A0 =C2=A0 <!-- XBean Finde= r helps to find annotations in classes=C2=A0
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=C2=A0if you uncomment this dependence, the fo= llowing error has fires:

Jun 12, 2014 3:40:46 PM org.apache.catalina.core.StandardCon= text listenerStart
SEVERE: Exception sending context initialized = event to listener instance of class com.sun.faces.config.ConfigureListener<= /div>
java.lang.RuntimeException: javax.enterprise.context.ContextNotActiveE= xception: WebBeans context with scope type annotation @FlowDefinition does = not exist within current thread
at com.sun.faces.config.ConfigureListener.contextInitiali= zed(ConfigureListener.java:273)
at org.apache.catal= ina.core.StandardContext.listenerStart(StandardContext.java:4887)
at org.apache.catalina.= core.StandardContext.startInternal(StandardContext.java:5381)

<dependency>
= <groupId>org.apache.xbean</groupId>
= <artifactId>xbean-finder</artifactId>
= <version>3.13</version>
= </dependency>
-->
<!-- =C2=A0-->
<dependency>
<groupId>org.apache.geronimo.bundles</groupId>
=
<artifactId>scan= notation</artifactId>
<version>1.0.2_1</versi= on>
= </dependency>

---------------------------------------= ---------------------------------------------------------------------------= ---------------- web Project

=C2=A0 <modelVersion>4.0.0</modelVersion>
=C2=A0= <parent>
<groupId>com.company</groupId>= ;
=C2=A0 <artifactId>= ;builder</artifactId>
=C2=A0 <version>0.2.1-SNAPSHOT</version>
=C2=A0 <relativePat= h>../Master/pom.xml</relativePath>
=C2=A0 </parent>
=C2=A0 <packaging>war</packa= ging>
=C2=A0 <artifactId>WebProject</artifactId>
=C2=A0 <name>WebProject</name>

<dependencies>
=C2=A0 =C2=A0 =C2=A0
<dependency>
<groupId>com.compa= ny</groupId>
<artifactId>= ;BusinessProject</artifactId>
<version>${project.version}</version>
</dependency>= ;

</dependencie= s>
----------------------------------------------------------------= ------------------------------------------------------------------ Business= Project

<project xmlns=3D"http://maven.apache.org/POM/4.0= .0" xmlns:xsi=3D"http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLoc= ation=3D"http://maven.ap= ache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
=C2=A0 <modelVersion>4.0.0</modelVersion>
=C2=A0= <parent>
<groupId>com.company&l= t;/groupId>
=C2=A0 <artifact= Id>builder</artifactId>
=C2=A0 <version>0.2.1-SNAPSHOT</version>
=C2=A0 <relati= vePath>../Master/pom.xml</relativePath>
=C2=A0 </parent>
=C2=A0 <packaging>jar</packa= ging>
=C2=A0 <artifactId>BusinessProject</arti= factId>
=C2=A0 <name>BusinessProject</name>
<= div>


2014-06-12 14:52 GMT-03:00 Mark Struberg <= struberg@yahoo.de>:
Hi Felipe!

Let me first ask you what you intend to do. I like to learn about you= r use case and then we should be able to help you.

Your sample shows a class (Permissao)=C2=A0which has no qualifier annotations at all.=C2=A0

But your sample also shows a Qualifier @BusinessBean. Where do you us= e it?
Do you get a BeanManager at all?

Do you have your sample online somewhere? Maybe on github?
That would really make it easier for us to help you.

LIeGrue,
strub



On Thursday, 12 June 2014, 19:11, = Felipe Pina <fop.= net@gmail.com> wrote:



but still no success =C2=A0:(=C2=A0

@SuppressW= arnings("unchecked")
public static <T> T getCont= extualInstance(final Class<T> type) {
= BeanManager manager =3D getBeanManager();
=C2=A0 =C2=A0T result= =3D null;
= =C2=A0 =C2=A0
=C2=A0 =C2=A0@SuppressWarnings("serial"= )
Annot= ation[] annotations =3D { new AnnotationLiteral<BusinessBean>() {} };=
=C2=A0 =C2=A0 =C2=A0 =C2=A0=C2=A0=
Set<Bean<?>> beans =3D manager.getBeans(type, anno= tations);=C2=A0-> empty=
= beans =3D manager.getBeans(type); =C2=A0-> empty
beans =3D m= anager.getBeans("teste");=C2=A0-> empty
= Bean<T> bean =3D (Bean<T>) manager.resolve(beans);
=
= =C2=A0 =C2=A0if (bean !=3D null) {
= =C2=A0 =C2=A0 =C2=A0 =C2=A0CreationalContext<T> context =3D manager.c= reateCreationalContext(bean);
=C2=A0 =C2=A0 =C2=A0 =C2=A0if (co= ntext !=3D null) {
= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0result =3D (T) manager.getReferenc= e(bean, type, context);
=C2=A0 =C2=A0 =C2=A0 =C2=A0}
= =C2=A0 =C2=A0}
=C2=A0 =C2=A0return result;
}<= /div>

My dependencies=C2=A0

=C2=A0<properties>
=C2=A0 <openwebbeans.version>1.2.1</openwebbeans.version>
</properties>
=
=C2=A0 =C2=A0 <dependen= cy>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 <groupId>org.apache.geronim= o.specs</groupId>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 <artifactId>geronimo-a= tinject_1.0_spec</artifactId>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 <version>1.0</version>
=C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 <scope>compile</scope>
= =C2=A0 =C2=A0 =C2=A0 =C2=A0 </dependency>
=C2=A0 =C2=A0= =C2=A0 =C2=A0 <!-- JSR-299 =C2=A0-->
=C2=A0 =C2=A0 =C2=A0 = =C2=A0 <dependency>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 <groupId>org.apache.geronimo.specs</groupId>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 <artifactId>geronimo-jcdi_1= .0_spec</artifactId>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 <version>1.0</version>
=C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 <scope>compile</scope>
=C2=A0 =C2= =A0 =C2=A0 =C2=A0 </dependency>

=C2=A0 =C2=A0 =C2=A0 =C2=A0 <dependen= cy>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 <groupId>o= rg.apache.geronimo.specs</groupId>
=C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 <artifactId>geronimo-interceptor_1.1_spec</artif= actId>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 <version>1.0</version>= ;
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 <scope>compile&= lt;/scope>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 </dependency>
=C2=A0 =C2=A0 =C2=A0 = =C2=A0=C2=A0
=C2=A0 =C2=A0 =C2=A0 =C2=A0 <dependency>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 <groupId>org.apache.op= enwebbeans</groupId>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 <artifactId>openwebbeans-impl</artifactId>
=C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 <version>${openwebbeans.version}&= lt;/version>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 <scope>runtime</sco= pe>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 </dependency>
=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 <dependency>= ;
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 <groupId>org.ap= ache.openwebbeans</groupId>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 <artifactId>openwebbea= ns-web</artifactId>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 <version>${openwebbeans.version}</version>
=C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 <scope>runtime</scope>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 </dependency>
=C2=A0 =C2=A0 =C2=A0 =C2=A0=C2=A0
=C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0<!-- SPI (Service Provider Interface). -->
=C2=A0= =C2=A0 <dependency>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 <groupId>org.apache= .openwebbeans</groupId>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 <artifactId>openwebbea= ns-spi</artifactId>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 <version>${openwebbeans.version}</version>
=C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 <scope>runtime</scope>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 </dependency> =C2=A0 =C2=A0




2014-06-12 10:03 GMT-03:00 Tho= mas Andraschko <andraschko.thoma= s@gmail.com>:
Maybe you miss the beans.xml in your jar but= the way how you call #getBeans with an qualifier is wrong.


2014-06-12 14:55 GMT+= 02:00 Felipe Pina <fop.net@gmail.com&g= t;:

Take a look to my tests. The focus is not ho= w am i passing as parameter annotation, because the lookup by name works to= bean inside WebProject but not works to bean inside BusinessProject

I have tested using three ways of lookup the bean, and both of b= ean are annotated similarly, but the webproject bean works and the Bussines= sProject bean do not works (jar package).

Set<Bean<?>> bean= s =3D manager.getBeans(type, type.getAnnotation(BusinessBean.class));
=
Set<Bean<?>>= beans =3D manager.getBeans(type);
Set<Bean<?>>= beans =3D manager.getBeans("teste");




2014-06-12 9:34 GMT-03:00 Thomas Andraschko <andraschko.thomas@gmail.com>:

You need to a pass a AnnotationLiteral instance = instead of "type.getAnnotation(yourAnnotation.class)"
Here it's explained how to create one and use one: http://deltaspike.apache.org/core.html#bea= nprovider



<= div>2014-06-12 14:26 GMT+02:00 Gerhard Petracek <gerhard.petracek@gmail.com>:

@felipe:
we won't respond some= thing different (see [1]), if you keep the wrong code.
the one case you mentioned just works, because #getAnnotation returns = null.

regards,
gerhard



2014-06-12 14:16 GMT+02:00 Thomas Andraschko <andraschko.thomas@gmail.com>:

Have a look at the bean manager java doc -&g= t;

getBeans(java.lang.refle= ct.Type=C2=A0beanType, java.lang.annotation.Annotation...=C2=A0qualifiers)

RequestScoped isn't a CDI q= ualifier! ;)


2014-06-12 14:03 GMT+02:00 Felipe Pina <fop.net@gmail.com>:

Questions

  1. Is t= here any schema that uses in the beans.xml file that configures the engine = to evaluate candidates beans through a package path?
  2. the fact that the bean be package= d inside a jar which in turn, within a war, is impediment to the proper fun= ctioning of the injection of bean?


Tests=C2=A0
  1. lookup bean from s= tring value
  1. lookup "teste" -> works fine
  2. lookup = "perm" -> fail returning null
  • lookup bean from type
  1. lookup using = Permissao.class -> =C2=A0fail returning null


Project Structure

= WAR
= =C2=A0 |- WebProject
=C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 |- com.company.bean.JSFBean =C2=A0->=C2=A0<= /b>@Named(value=3D"teste")
=C2=A0 |- =C2=A0BusinessProject
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0|- com.company.bean.Permissao ->=C2=A0@Named(value=3D"perm")=C2=A0@BusinessBean<= /div>

= My Qualifier

@Qualifier
@Retention(RUNTIME)
@Targe= t({TYPE, METHOD, FIELD, PARAMETER})
public @interface Bus= inessBean {

}

My bean.

@javax.enterprise.context.RequestScoped
@javax.ente= rprise.inject.Default
public class Permissao e= xtends NegocioBase<PermissaoDTO> {=C2=A0
....
}


context.xml
=C2=A0<Resource name=3D"BeanManager= "=C2=A0
=C2=A0 =C2=A0 =C2=A0 =C2=A0 auth=3D"Container"
=C2=A0 =C2=A0 =C2=A0 =C2=A0 type=3D"javax.enterprise.inject.spi.B= eanManager"
=C2=A0 =C2=A0 =C2=A0 =C2=A0 factory=3D"org.= apache.webbeans.container.ManagerObjectFactory"/>
<= br clear=3D"none">

web.xml

<!-- I ran with and without this= resource-env-ref section -->
=C2=A0 <resource-env-ref><= /div>
=C2=A0 =C2=A0 <description>Object factory for the CDI Bean = Manager</description>
=C2=A0 =C2=A0 <resource-env-ref-name>BeanManager</resource-en= v-ref-name>
<r= esource-env-ref-type>javax.enterprise.inject.spi.BeanManager</resourc= e-env-ref-type>
=C2=A0 </resource-env-ref>

BeanFactory

pu= blic class BeanFactory {
static BeanManager getBea= nManager() {
=C2=A0=C2=A0 =C2=A0Initia= lContext context;
= =C2=A0=C2=A0 =C2=A0Object result;
=C2=A0=C2=A0 =C2=A0try {
=C2=A0=C2=A0 =C2=A0 =C2=A0 =C2= =A0context =3D new InitialContext();
=C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0result =3D context.lookup= ("java:comp/env/BeanManager"); //lookup in Tomcat
=C2=A0=C2=A0 =C2=A0} catc= h (NamingException e) {
=C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0try {
=C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0conte= xt =3D new InitialContext();
=C2=A0=C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0result =3D context.lookup("java:comp/BeanManag= er"); //lookup in JBossAS
=C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0} catch (NamingException ex) {<= /div>
=C2=A0=C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0throw new RuntimeException("BeanManager could = not be found in JNDI", e);
=C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0}
=C2=A0=C2=A0 =C2=A0}
=C2=A0=C2=A0 =C2=A0return= (BeanManager) result;
}
@SuppressWarnings("unchecked&= quot;)
public static <T> T= getContextualInstance(final Class<T> type) {
BeanManager manager =3D getBeanManager()= ;
=C2=A0=C2=A0 =C2=A0T resu= lt =3D null;
Set<Bean<?>> beans =3D manager.getBeans(ty= pe, type.getAnnotation(RequestScoped.class));
---- > =C2=A0why variable beans isEmpty = !!!
Bean= <T> bean =3D (Bean<T>) manager.resolve(beans);
=C2=A0=C2=A0 =C2=A0if (bean !=3D nul= l) {
=C2=A0=C2=A0 =C2=A0 =C2= =A0 =C2=A0CreationalContext<T> context =3D manager.createCreationalCo= ntext(bean);
=C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0if (context !=3D null) {
=C2=A0=C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0result =3D (T) manager.getReference(bean, type, con= text);
=C2=A0=C2=A0 = =C2=A0 =C2=A0 =C2=A0}
=C2=A0=C2=A0 =C2=A0}
=C2=A0=C2=A0 =C2=A0return= result;
}
}

--
Atenciosamente,
Felipe Pina






--
Atenciosamente,
Felipe Pina




--
Atenciosamente,
Fe= lipe Pina





--
Atenciosamente,
Felipe Pina
--20cf303a2f81e8943204fba80062--