I agree that it is more likely an EJB integration issue.
But @Specializes on EJBs is even explicitly defined to work in the EE specs (in 
both the CDI and umbrella specs afair).

LieGrue,
strub


> Am 24.09.2017 um 23:41 schrieb John D. Ament <[email protected]>:
> 
> The error you're getting is more to do with EJB than it does with CDI.
> JBoss AS 7 is very old.  I doubt specializing an EJB would have ever worked
> (I'm not even sure it works today, specializing is more to do with how CDI
> works).  Does it need to be an EJB?
> 
> On Sun, Sep 24, 2017 at 4:59 PM Antonio <[email protected]> wrote:
> 
>> Hi all,
>> We’re working in a java Project and we wanted to extend our application
>> with specialization beans in external classes.
>> 
>> We were trying to include one of those beans to our context dynamically
>> using DeltaSpike. This bean specializes another one, as you can see in the
>> code below:
>> 
>> @Stateless
>> public ClassA implements InterfaceA {…}
>> 
>> @Stateless
>> @Specializes
>> public class SpecializationOfClassA extends ClassA {…}
>> 
>> Firstly we tried to use BeforeBeanDiscovery event to add the annotated
>> type to the Bean manager:
>> 
>> public void beforeBeanDiscovery(@Observes BeforeBeanDiscovery bbd,
>> BeanManager bm) {
>>        try {
>>               final javax.enterprise.inject.spi.AnnotatedType<?> at =
>> bm.createAnnotatedType(SpecializationOfClassA.class);
>>               bbd.addAnnotatedType(at);
>> . . .
>> 
>> The above code triggered the following exception: WELD-000047 Specializing
>> bean must extend another bean
>> This makes no sense for us, because the class we are passing extends
>> another one.
>> 
>> Then we tried to use AfterBeanDiscovery event to include the new bean to
>> the bean manager:
>> 
>> public void addCdiBeans(final @Observes AfterBeanDiscovery abd, final
>> BeanManager bm) throws Exception {
>>              AnnotatedType<Object> annotatedType = new
>> AnnotatedTypeBuilder().readFromType(SpecializationOfClassA.class).create();
>>              final InjectionTarget it =
>> bm.createInjectionTarget(annotatedType);
>>              final BeanBuilder<Object> beanBuilder =
>>                                           new BeanBuilder<Object>(bm)
>> 
>> .readFromType(annotatedType)
>> 
>> .injectionPoints(it.getInjectionPoints())
>>                                                         ;
>>              final Bean<Object> cdiBean = beanBuilder.create();
>>              abd.addBean(cdiBean);
>> }
>> 
>> The code above does not trigger any exceptions but it does not work
>> because ClassA is injected instead of its specialization
>> SpecializationOfClassA.
>> 
>> We are deploying the application in JBoss 7.1.1.
>> Do you know if this would be posible using DeltaSpike or there’s a problem
>> with specialization classes?
>> 
>> Thanks a lot and best regards.
>> 


.

Reply via email to