You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openwebbeans.apache.org by "John D. Ament" <jo...@apache.org> on 2017/07/21 19:10:33 UTC

OWB 2 not firing ProcessAnnotatedType for all bean classes

I do something really lazy, I have an extension that has this method on it:

public void findEntities(@Observes @WithAnnotations(Entity.class)
ProcessAnnotatedType<?> pat)

which just looks for entity classes.  They're not going to be CDI beans,
but they are annotated types.  Per the spec,
https://docs.jboss.org/cdi/api/2.0/javax/enterprise/inject/spi/ProcessAnnotatedType.html
,
the event should get fired, even if there are no bean defining annotations.

Switching beans.xml to use bean-discovery-mode=all fixes it, but I'd prefer
to not discover these as beans.

Using a <beans bean-discovery-mode="all" version="2.0"><trim/></beans> does
fix it. But either way, my understanding is that PAT is always fired, for
all classes found within a bean archive.

John

Re: OWB 2 not firing ProcessAnnotatedType for all bean classes

Posted by Romain Manni-Bucau <rm...@gmail.com>.
While you accept scanning is undefined - Im not sure it can integrate the
spec cause all containers do it differently, even a single container can
have multiple modes :s - then a type was discovered means nothing except
for beans no?


Le 23 juil. 2017 16:09, "Eric Covener" <co...@gmail.com> a écrit :

> On Sun, Jul 23, 2017 at 8:13 AM, John D. Ament <jo...@apache.org>
> wrote:
> > We should probably review on cdi-dev.  I believe the intention behind
> > saying "classes discovered"  [1] is to indicate that its for all classes,
> > not just eligible beans.  Here's a use case: I have framework specific
> > classes, where the developer isn't required to add a scope.  Framework
> adds
> > the scope for them.  To do that, they use bean-discovery-mode=annotated
> and
> > PAT will add the dependent or other scope as appropriate.
> >
> > [1]:
> > https://docs.jboss.org/cdi/spec/1.2/cdi-spec.html#process_annotated_type
> >
> > On Sat, Jul 22, 2017 at 5:40 PM Mark Struberg <struberg@yahoo.de.invalid
> >
> > wrote:
> >
> >> In that case Romain is right.
> >>
> >> In an implicit BDA you only get PAT if the class has a bean defining
> >> annotation.
> >> Thats the reason we introduced all+trim.
>
>
> John alluded to changing, not adding, a beans.xml in the OP, so IIUC
> if it did not contain bean-discovery-mode=all + trim  then it seems to
> me that the type should have been processed.
>

Re: OWB 2 not firing ProcessAnnotatedType for all bean classes

Posted by Mark Struberg <st...@yahoo.de.INVALID>.
Having no beans.xml (aka implicit bean archive) or a bean-discovery-mode="annotated" will make the 'Type discovery' have only pick up concrete classes which are annotated with a 'bean defining annotation'.
And thus we can only fire a ProcessAnnoatedType event for those classes. We don't know about the others at this stage.

We don't get any PAT for interfaces, enums, abstract classes, classes without explicit CDI scope, etc
That's the reason you e.g. cannot use a DeltaSpike @MessageBundle or DeltaSpike-Data in such bean archives.

That is that way as of CDI-1.1 and it's also TCK tested.

Note that per spec if you have an Extension in a jar then you MUST add a beans.xml if you have CDI beans in that jar.
In other words: a jar with an Extension is NOT an implicit bean archive. 

I'm pretty sure all this is well defined. But feel free to post on the spec list if you think there are some vaguely defined corner cases.

LieGrue,
strub


> Am 23.07.2017 um 16:09 schrieb Eric Covener <co...@gmail.com>:
> 
> On Sun, Jul 23, 2017 at 8:13 AM, John D. Ament <jo...@apache.org> wrote:
>> We should probably review on cdi-dev.  I believe the intention behind
>> saying "classes discovered"  [1] is to indicate that its for all classes,
>> not just eligible beans.  Here's a use case: I have framework specific
>> classes, where the developer isn't required to add a scope.  Framework adds
>> the scope for them.  To do that, they use bean-discovery-mode=annotated and
>> PAT will add the dependent or other scope as appropriate.
>> 
>> [1]:
>> https://docs.jboss.org/cdi/spec/1.2/cdi-spec.html#process_annotated_type
>> 
>> On Sat, Jul 22, 2017 at 5:40 PM Mark Struberg <st...@yahoo.de.invalid>
>> wrote:
>> 
>>> In that case Romain is right.
>>> 
>>> In an implicit BDA you only get PAT if the class has a bean defining
>>> annotation.
>>> Thats the reason we introduced all+trim.
> 
> 
> John alluded to changing, not adding, a beans.xml in the OP, so IIUC
> if it did not contain bean-discovery-mode=all + trim  then it seems to
> me that the type should have been processed.


Re: OWB 2 not firing ProcessAnnotatedType for all bean classes

Posted by Eric Covener <co...@gmail.com>.
On Sun, Jul 23, 2017 at 8:13 AM, John D. Ament <jo...@apache.org> wrote:
> We should probably review on cdi-dev.  I believe the intention behind
> saying "classes discovered"  [1] is to indicate that its for all classes,
> not just eligible beans.  Here's a use case: I have framework specific
> classes, where the developer isn't required to add a scope.  Framework adds
> the scope for them.  To do that, they use bean-discovery-mode=annotated and
> PAT will add the dependent or other scope as appropriate.
>
> [1]:
> https://docs.jboss.org/cdi/spec/1.2/cdi-spec.html#process_annotated_type
>
> On Sat, Jul 22, 2017 at 5:40 PM Mark Struberg <st...@yahoo.de.invalid>
> wrote:
>
>> In that case Romain is right.
>>
>> In an implicit BDA you only get PAT if the class has a bean defining
>> annotation.
>> Thats the reason we introduced all+trim.


John alluded to changing, not adding, a beans.xml in the OP, so IIUC
if it did not contain bean-discovery-mode=all + trim  then it seems to
me that the type should have been processed.

Re: OWB 2 not firing ProcessAnnotatedType for all bean classes

Posted by "John D. Ament" <jo...@apache.org>.
We should probably review on cdi-dev.  I believe the intention behind
saying "classes discovered"  [1] is to indicate that its for all classes,
not just eligible beans.  Here's a use case: I have framework specific
classes, where the developer isn't required to add a scope.  Framework adds
the scope for them.  To do that, they use bean-discovery-mode=annotated and
PAT will add the dependent or other scope as appropriate.

[1]:
https://docs.jboss.org/cdi/spec/1.2/cdi-spec.html#process_annotated_type

On Sat, Jul 22, 2017 at 5:40 PM Mark Struberg <st...@yahoo.de.invalid>
wrote:

> In that case Romain is right.
>
> In an implicit BDA you only get PAT if the class has a bean defining
> annotation.
> Thats the reason we introduced all+trim.
>
> LieGrue,
> Strub
>
> > Am 21.07.2017 um 21:37 schrieb Romain Manni-Bucau <rmannibucau@gmail.com
> >:
> >
> > Cause the scanning by itself is undefined, you can not scan skip not bean
> > types and be spec compliant.
> >
> >
> > Le 21 juil. 2017 21:26, "John D. Ament" <jo...@apache.org> a écrit
> :
> >
> >> Errr I'm not sure what you mean.  The spec states this "before it reads
> the
> >> declared annotations" so I'm not sure why you think it needs to have a
> bean
> >> defining annotation.
> >>
> >> John
> >>
> >> On Fri, Jul 21, 2017 at 3:21 PM Romain Manni-Bucau <
> rmannibucau@gmail.com>
> >> wrote:
> >>
> >>> Hmm, interesting edge case. For me it should be ignored until you make
> it
> >>> scanned using @Dependent or so. But fear it is quite undefined or
> >>> "interpretable"
> >>>
> >>> Le 21 juil. 2017 21:10, "John D. Ament" <jo...@apache.org> a
> écrit
> >> :
> >>>
> >>>> I do something really lazy, I have an extension that has this method
> on
> >>> it:
> >>>>
> >>>> public void findEntities(@Observes @WithAnnotations(Entity.class)
> >>>> ProcessAnnotatedType<?> pat)
> >>>>
> >>>> which just looks for entity classes.  They're not going to be CDI
> >> beans,
> >>>> but they are annotated types.  Per the spec,
> >>>> https://docs.jboss.org/cdi/api/2.0/javax/enterprise/inject/spi/
> >>>> ProcessAnnotatedType.html
> >>>> ,
> >>>> the event should get fired, even if there are no bean defining
> >>> annotations.
> >>>>
> >>>> Switching beans.xml to use bean-discovery-mode=all fixes it, but I'd
> >>> prefer
> >>>> to not discover these as beans.
> >>>>
> >>>> Using a <beans bean-discovery-mode="all" version="2.0"><trim/></beans>
> >>> does
> >>>> fix it. But either way, my understanding is that PAT is always fired,
> >> for
> >>>> all classes found within a bean archive.
> >>>>
> >>>> John
> >>>>
> >>>
> >>
>
>

Re: OWB 2 not firing ProcessAnnotatedType for all bean classes

Posted by Mark Struberg <st...@yahoo.de.INVALID>.
In that case Romain is right.

In an implicit BDA you only get PAT if the class has a bean defining annotation.
Thats the reason we introduced all+trim.

LieGrue,
Strub

> Am 21.07.2017 um 21:37 schrieb Romain Manni-Bucau <rm...@gmail.com>:
> 
> Cause the scanning by itself is undefined, you can not scan skip not bean
> types and be spec compliant.
> 
> 
> Le 21 juil. 2017 21:26, "John D. Ament" <jo...@apache.org> a écrit :
> 
>> Errr I'm not sure what you mean.  The spec states this "before it reads the
>> declared annotations" so I'm not sure why you think it needs to have a bean
>> defining annotation.
>> 
>> John
>> 
>> On Fri, Jul 21, 2017 at 3:21 PM Romain Manni-Bucau <rm...@gmail.com>
>> wrote:
>> 
>>> Hmm, interesting edge case. For me it should be ignored until you make it
>>> scanned using @Dependent or so. But fear it is quite undefined or
>>> "interpretable"
>>> 
>>> Le 21 juil. 2017 21:10, "John D. Ament" <jo...@apache.org> a écrit
>> :
>>> 
>>>> I do something really lazy, I have an extension that has this method on
>>> it:
>>>> 
>>>> public void findEntities(@Observes @WithAnnotations(Entity.class)
>>>> ProcessAnnotatedType<?> pat)
>>>> 
>>>> which just looks for entity classes.  They're not going to be CDI
>> beans,
>>>> but they are annotated types.  Per the spec,
>>>> https://docs.jboss.org/cdi/api/2.0/javax/enterprise/inject/spi/
>>>> ProcessAnnotatedType.html
>>>> ,
>>>> the event should get fired, even if there are no bean defining
>>> annotations.
>>>> 
>>>> Switching beans.xml to use bean-discovery-mode=all fixes it, but I'd
>>> prefer
>>>> to not discover these as beans.
>>>> 
>>>> Using a <beans bean-discovery-mode="all" version="2.0"><trim/></beans>
>>> does
>>>> fix it. But either way, my understanding is that PAT is always fired,
>> for
>>>> all classes found within a bean archive.
>>>> 
>>>> John
>>>> 
>>> 
>> 


Re: OWB 2 not firing ProcessAnnotatedType for all bean classes

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Cause the scanning by itself is undefined, you can not scan skip not bean
types and be spec compliant.


Le 21 juil. 2017 21:26, "John D. Ament" <jo...@apache.org> a écrit :

> Errr I'm not sure what you mean.  The spec states this "before it reads the
> declared annotations" so I'm not sure why you think it needs to have a bean
> defining annotation.
>
> John
>
> On Fri, Jul 21, 2017 at 3:21 PM Romain Manni-Bucau <rm...@gmail.com>
> wrote:
>
> > Hmm, interesting edge case. For me it should be ignored until you make it
> > scanned using @Dependent or so. But fear it is quite undefined or
> > "interpretable"
> >
> > Le 21 juil. 2017 21:10, "John D. Ament" <jo...@apache.org> a écrit
> :
> >
> > > I do something really lazy, I have an extension that has this method on
> > it:
> > >
> > > public void findEntities(@Observes @WithAnnotations(Entity.class)
> > > ProcessAnnotatedType<?> pat)
> > >
> > > which just looks for entity classes.  They're not going to be CDI
> beans,
> > > but they are annotated types.  Per the spec,
> > > https://docs.jboss.org/cdi/api/2.0/javax/enterprise/inject/spi/
> > > ProcessAnnotatedType.html
> > > ,
> > > the event should get fired, even if there are no bean defining
> > annotations.
> > >
> > > Switching beans.xml to use bean-discovery-mode=all fixes it, but I'd
> > prefer
> > > to not discover these as beans.
> > >
> > > Using a <beans bean-discovery-mode="all" version="2.0"><trim/></beans>
> > does
> > > fix it. But either way, my understanding is that PAT is always fired,
> for
> > > all classes found within a bean archive.
> > >
> > > John
> > >
> >
>

Re: OWB 2 not firing ProcessAnnotatedType for all bean classes

Posted by "John D. Ament" <jo...@apache.org>.
Errr I'm not sure what you mean.  The spec states this "before it reads the
declared annotations" so I'm not sure why you think it needs to have a bean
defining annotation.

John

On Fri, Jul 21, 2017 at 3:21 PM Romain Manni-Bucau <rm...@gmail.com>
wrote:

> Hmm, interesting edge case. For me it should be ignored until you make it
> scanned using @Dependent or so. But fear it is quite undefined or
> "interpretable"
>
> Le 21 juil. 2017 21:10, "John D. Ament" <jo...@apache.org> a écrit :
>
> > I do something really lazy, I have an extension that has this method on
> it:
> >
> > public void findEntities(@Observes @WithAnnotations(Entity.class)
> > ProcessAnnotatedType<?> pat)
> >
> > which just looks for entity classes.  They're not going to be CDI beans,
> > but they are annotated types.  Per the spec,
> > https://docs.jboss.org/cdi/api/2.0/javax/enterprise/inject/spi/
> > ProcessAnnotatedType.html
> > ,
> > the event should get fired, even if there are no bean defining
> annotations.
> >
> > Switching beans.xml to use bean-discovery-mode=all fixes it, but I'd
> prefer
> > to not discover these as beans.
> >
> > Using a <beans bean-discovery-mode="all" version="2.0"><trim/></beans>
> does
> > fix it. But either way, my understanding is that PAT is always fired, for
> > all classes found within a bean archive.
> >
> > John
> >
>

Re: OWB 2 not firing ProcessAnnotatedType for all bean classes

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Hmm, interesting edge case. For me it should be ignored until you make it
scanned using @Dependent or so. But fear it is quite undefined or
"interpretable"

Le 21 juil. 2017 21:10, "John D. Ament" <jo...@apache.org> a écrit :

> I do something really lazy, I have an extension that has this method on it:
>
> public void findEntities(@Observes @WithAnnotations(Entity.class)
> ProcessAnnotatedType<?> pat)
>
> which just looks for entity classes.  They're not going to be CDI beans,
> but they are annotated types.  Per the spec,
> https://docs.jboss.org/cdi/api/2.0/javax/enterprise/inject/spi/
> ProcessAnnotatedType.html
> ,
> the event should get fired, even if there are no bean defining annotations.
>
> Switching beans.xml to use bean-discovery-mode=all fixes it, but I'd prefer
> to not discover these as beans.
>
> Using a <beans bean-discovery-mode="all" version="2.0"><trim/></beans> does
> fix it. But either way, my understanding is that PAT is always fired, for
> all classes found within a bean archive.
>
> John
>