Hello,
i deployed an webapp application to Glassfish 3.1.1 (12) which uses CDI for
instantiation and
injection (activiti-engine and activiti-cdi). I have the following content in
WEB-INF/beans.xml:
<?xml version="1.0" encoding="UTF-8"?> <beans
xmlns="
http://java.sun.com/xml/ns/javaee"
xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/beans_1_0.xsd"> <alternatives>
<class>org.activiti.cdi.impl.LocalProcessEngineLookup</class>
</alternatives> </beans>
the following code does a search via the BeanManager to get to an instance of
the interface ProcessEngineLookup.class:
public static <T> T lookup(Class<T> clazz) { BeanManager bm =
BeanManagerLookup.getBeanManager(); Bean<T> bean = (Bean<T>)
bm.getBeans(clazz).iterator().next(); CreationalContext<T> ctx =
bm.createCreationalContext(bean); T dao = (T) bm.getReference(bean, clazz,
ctx); return dao; }
but unfortunately i get the following exception because the
bm.getBeans(clazz)
call is not able to bind a corresponding managed bean. When i debug the code
then i can see that the BeanManager lists three implementations of the
ProcessEngineLookup
interface, amongst them is the desired LocalProcessEngineLookup bean.
SCHWERWIEGEND: Exception while loading the app : Exception List with 1
exceptions: Exception 0 : java.util.NoSuchElementException at
java.util.HashMap$HashIterator.nextEntry(HashMap.java:796) at
java.util.HashMap$KeyIterator.next(HashMap.java:828) at
org.activiti.cdi.impl.util.ProgrammaticBeanLookup.lookup(ProgrammaticBeanLookup.java:29)
at
org.activiti.cdi.impl.ActivitiExtension.initializeProcessEngine(ActivitiExtension.java:83)
at
org.activiti.cdi.impl.ActivitiExtension.afterDeploymentValidation(ActivitiExtension.java:69)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597) at
org.jboss.weld.util.reflection.SecureReflections$13.work(SecureReflections.java:305)
at
org.jboss.weld.util.reflection.SecureReflectionAccess.run(SecureReflectionAccess.java:54)
at
org.jboss.weld.util.reflection.SecureReflectionAccess.runAsInvocation(SecureReflectionAccess.java:163)
at
org.jboss.weld.util.reflection.SecureReflections.invoke(SecureReflections.java:299)
at
org.jboss.weld.introspector.jlr.WeldMethodImpl.invokeOnInstance(WeldMethodImpl.java:188)
at
org.jboss.weld.introspector.ForwardingWeldMethod.invokeOnInstance(ForwardingWeldMethod.java:59)
at
org.jboss.weld.injection.MethodInjectionPoint.invokeOnInstanceWithSpecialValue(MethodInjectionPoint.java:198)
at
org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:282)
at
org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:265)
at
org.jboss.weld.event.ObserverMethodImpl.notify(ObserverMethodImpl.java:234)
at
org.jboss.weld.bootstrap.events.AbstractContainerEvent.fire(AbstractContainerEvent.java:88)
at
org.jboss.weld.bootstrap.events.AbstractDeploymentContainerEvent.fire(AbstractDeploymentContainerEvent.java:52)
at
org.jboss.weld.bootstrap.events.AfterDeploymentValidationImpl.fire(AfterDeploymentValidationImpl.java:34)
at
org.jboss.weld.bootstrap.WeldBootstrap.validateBeans(WeldBootstrap.java:399)
at org.glassfish.weld.WeldDeployer.event(WeldDeployer.java:190) at
org.glassfish.kernel.event.EventsImpl.send(EventsImpl.java:128) at
org.glassfish.internal.data.ApplicationInfo.start(ApplicationInfo.java:306)
at
com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:462)
at
com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:240)
The interface which is used for the lookup looks like this:
public interface ProcessEngineLookup { ProcessEngine getProcessEngine(); void
ungetProcessEngine(); }
and the bean implementing the interface looks like this:
import javax.enterprise.inject.Alternative; import
org.activiti.engine.ProcessEngine; @Alternative public class
LocalProcessEngineLookup implements ProcessEngineLookup { @Override public
ProcessEngine getProcessEngine() { } @Override public void
ungetProcessEngine() { }
I dont know if this is related to a problem with the configuration of CDI, or
something with Glassfish?
Or i am using this CDI mechanism in a wrong context, like in a web app?
Thanks in advance
--
[Message sent by forum member 'chris.joelly']
View Post: http://forums.java.net/node/832426