After the migration of a JEE application (from JBoss 7.1.1 to WildFly 8.2.1) our method to get CDI Beans stopped working. The application have several modules (independent JAR files) grouped into one WAR file deployed now on WildFly.
The Bean to be injected is in the module service
and it is implementing the interface IProcessor
:
@Loggable
@Monitorable
@Singleton
@ConcurrencyManagement(CONTAINER)
@Lock(READ)
@LocalBean
@ApplicationScoped
public class Processor implements IProcessor {
[...]
In another module of the application (common
) there is the rest of the logic: the interface IProcessor
and the class where we search for it.
This is how the BeanManager is retrieved:
public void keepBeanManager(@Observes AfterBeanDiscovery abd, BeanManager beanManager) {
bm = beanManager;
}
And this is how the call is done:
Set<Bean<?>> jobBeans = bm.getBeans(IProcessor.class);
I've tried printing out all deployed beans using Adam Bien's sample, at the same point as the getBeans
method is called, and I can see the Processor
in them. Also, if providing the full package and class name of the Processor
works as a temporal hack, but using the IProcessor
interface never works, jobBeans
is always empty.
The module service
is not visible to the module common
, and this is why the injection is done using the interface.
As it was working before in JBoss and not in WildFly I assume it is related with the way the AS is handling the Beans, could it be something missing in the configuration of WildFly after the migration?
As pointed by Xavier Dury in the comments, the Bean was not found because it was annotated as @LocalBean
. Removing the @LocalBean
annotation fixed the issue.
From the JEE definition of LocalBean:
Designates that a session bean exposes a no-interface view
As Processor
is implementing the interface IProcessor
, the annotation @LocalBean
should not be used.
What is strange still for me is why this was working on JBoss...