I am migrating my project to Wildfly10 and using cdi-api 1.2.
I have been using this structure to get the beanManager and then lookup some resources (example EJBs).
import javax.enterprise.inject.spi.BeanManager;
import javax.enterprise.inject.spi.CDI;
public abstract class ServiceLocator {
//....
private BeanManager getBeanManager() throws NamingException {
return CDI.current().getBeanManager();
}
public static <T> T lookup(Class<T> clazz) {
BeanManager manager = this.getBeanManager();
//...
}
This works fine using in a Servlet or a Filter.
However, when I use this same function in a MDB JMS like:
@MessageDriven(mappedName = MyQueueProcessor.QUEUE_NAME,
//...
public class RecebimentoMensagemCAM0021MDB {
@Override
protected void process(Object obj) {
MyServices service = ServiceLocator.lookup(MyServices.class);
//...
Occur this exception:
java.lang.IllegalStateException: WFLYWELD0039: Singleton not set for
ModuleClassLoader for Module "org.apache.activemq.artemis.ra:main"
from local module loader @629f0666 (finder: local module finder
@1bc6a36e (roots: /home/confidence/wildfly-
10.1.0.Final/modules,/home/confidence/wildfly-
10.1.0.Final/modules/system/layers/base)). This means that you are
trying to access a weld deployment with a Thread Context ClassLoader
that is not associated with the deployment.
at org.jboss.as.weld.services.ModuleGroupSingletonProvider$TCCLSingleton.get(ModuleGroupSingletonProvider.java:77)
at org.jboss.as.weld.services.ModuleGroupSingletonProvider$TCCLSingleton.get(ModuleGroupSingletonProvider.java:134)
at org.jboss.weld.Container.instance(Container.java:55)
at org.jboss.as.weld.WeldProvider.getCDI(WeldProvider.java:61)
at javax.enterprise.inject.spi.CDI.current(CDI.java:60)
at br.com.project.ServiceLocator.getBeanManager(ServiceLocator.java:xx)
at br.com.project.ServiceLocator.lookup(ServiceLocator.java:xx)
Anyone could help how to make this lookup works in the JMS.
Thanks in advance.