vaadin / cdi

CDI Integration for Vaadin
Apache License 2.0
41 stars 56 forks source link

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

Open maxusoltsev opened 8 years ago

maxusoltsev commented 8 years ago

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.

chergey commented 7 years ago

Could you post your solution?

maxusoltsev commented 7 years ago

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

chergey commented 7 years ago

Thank you a lot.

gotzl commented 7 years ago

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...