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.