cdi icon indicating copy to clipboard operation
cdi copied to clipboard

com.vaadin.cdi.internal.CDIUtil#lookupBeanManager cannot find BeanManager in jetty

Open maxusoltsev opened this issue 9 years ago • 4 comments

Hello ! When using jetty-maven-plugin 9.3.9.v20160517 and vaadin-cdi 1.0.3, UIs annnotated as @CDIUI does not work, i think becouse jetty does not expose BeasManager as "java:comp/BeanManager", "java:comp/env/BeanManager" jndi names, so com.vaadin.cdi.internal.CDIUtil#lookupBeanManager returns null (but @Inject works). It can be resolved by using CDI.current().getBeanManager() (and it works) instead of lookup, but javax.enterprise.inject.spi.CDI is availible only in javaee 7 api (CDI 1.1), and vaadin-cdi uses javaee-api 6. I resolved this issue locally by overriding com.vaadin.cdi.CDIUIProvider , VaadinCDIServlet, etc, but maybe there is some simpler way ? Thank you.

maxusoltsev avatar Oct 21 '16 12:10 maxusoltsev

Could you post your solution?

chergey avatar Feb 27 '17 01:02 chergey

Please take a look on https://github.com/maxusoltsev/vaadin-jetty-cdi

maxusoltsev avatar Feb 27 '17 06:02 maxusoltsev

Thank you a lot.

chergey avatar Feb 27 '17 07:02 chergey

In case s.o. is interested, I've used s.t. like this:

public class MyExtension implements Extension { void afterBeanDiscovery(@Observes AfterBeanDiscovery abd, BeanManager bm) { try { InitialContext ic = new InitialContext(); ic.bind("java:comp/BeanManager", bm); } catch (NamingException e1) { } try { InitialContext ic = new InitialContext(); ic.bind("java:comp/env/BeanManager", bm); } catch (NamingException e1) { } } } and a file META-INF/services/javax.enterprise.inject.spi.Extension advertising the extension...

gotzl avatar May 01 '17 08:05 gotzl