You kept owb in web-inf/lib? Le 9 nov. 2013 13:22, "aljesco" <[email protected]> a écrit :
> I added > <Listener > className="org.apache.webbeans.web.tomcat.ContextLifecycleListener" /> > into server.xml files. > After that Tomcat throwed several ClassNotFoundExceptions because it > couldn't find OWB libs. I > put openwebbeans-impl-1.2.0.jar, openwebbeans-spi-1.2.0.jar, > openwebbeans-tomcat7-1.2.0.jar > and openwebbeans-web-1.2.0.jar into lib folder. Now Tomcat fails to start > with exception > ==== > Caused by: java.lang.RuntimeException: java.lang.ClassCastException: > Cannot cast org.apache.webbeans.service.DefaultLoaderService to > org.apache.webbeans.spi.LoaderService > at > org.apache.webbeans.web.tomcat.ContextLifecycleListener.containerEvent(ContextLifecycleListener.java:200) > at > org.apache.catalina.core.ContainerBase.fireContainerEvent(ContainerBase.java:1398) > at > org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4944) > at > org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5434) > at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) > ... 10 more > Caused by: java.lang.ClassCastException: Cannot cast > org.apache.webbeans.service.DefaultLoaderService to > org.apache.webbeans.spi.LoaderService > at java.lang.Class.cast(Class.java:3094) > at > org.apache.webbeans.config.WebBeansContext.<init>(WebBeansContext.java:121) > at > org.apache.webbeans.config.WebBeansContext.<init>(WebBeansContext.java:98) > at > org.apache.webbeans.corespi.DefaultSingletonService.get(DefaultSingletonService.java:54) > at > org.apache.webbeans.corespi.DefaultSingletonService.get(DefaultSingletonService.java:28) > at > org.apache.webbeans.config.WebBeansFinder.getSingletonInstance(WebBeansFinder.java:51) > at > org.apache.webbeans.config.WebBeansContext.getInstance(WebBeansContext.java:164) > at > org.apache.webbeans.config.WebBeansContext.currentInstance(WebBeansContext.java:182) > at org.apache.webbeans.web.tomcat.TomcatUtil.inject(TomcatUtil.java:38) > at > org.apache.webbeans.web.tomcat.ContextLifecycleListener.containerEvent(ContextLifecycleListener.java:182) > ... 14 more > ==== > What I'm doing wrong? > > > 2013/11/9 Romain Manni-Bucau <[email protected]> > >> this one as tomcat listener >> https://github.com/apache/openwebbeans/blob/trunk/webbeans-tomcat7/src/main/java/org/apache/webbeans/web/tomcat/ContextLifecycleListener.java >> Le 9 nov. 2013 12:36, "aljesco" <[email protected]> a écrit : >> >> No, I didn't set it. What class should I set up as a listener? >>> >>> Do I need this lines in web.xml? >>> >>> <listener> >>> >>> <listener-class>org.apache.webbeans.servlet.WebBeansConfigurationListener</listener-class> >>> </listener> >>> <resource-env-ref> >>> <resource-env-ref-name>BeanManager</resource-env-ref-name> >>> >>> <resource-env-ref-type>javax.enterprise.inject.spi.BeanManager</resource-env-ref-type> >>> </resource-env-ref> >>> >>> >>> 2013/11/9 Romain Manni-Bucau <[email protected]> >>> >>>> Hi >>>> >>>> Api jars are geronimo*spec ones (jcdi and atinject IIRC) >>>> >>>> In tomcat you need tomcat owb listener to get servlet injection, did >>>> you set it? >>>> Le 9 nov. 2013 12:13, "aljesco" <[email protected]> a écrit : >>>> >>>> Hello everyone, >>>>> >>>>> I've tried to get OWB working for about several hours on Tomcat 7 and >>>>> afterall I got really confused. >>>>> I'd be very thankful if someone can clarify some points with OWB. >>>>> >>>>> So, I'm developing a test project with just one servlet >>>>> >>>>> ==== >>>>> @WebServlet(urlPatterns="/test") >>>>> public class extends HttpServlet { >>>>> >>>>> private @Inject MyService s; >>>>> @Override >>>>> protected void doGet(HttpServletRequest req, HttpServletResponse >>>>> resp) throws ServletException, IOException { >>>>> >>>>> WebBeansContext currentInstance = WebBeansContext.currentInstance(); >>>>> MyService s2 = currentInstance.get(MyService.class); >>>>> resp.getWriter().println(s); >>>>> resp.getWriter().println("s2: " + s2.getHash()); >>>>> } >>>>> } >>>>> ==== >>>>> >>>>> it tries get injected MyService instance which is POJO: >>>>> >>>>> ==== >>>>> public class MyService { >>>>> public MyService() { >>>>> } >>>>> public String getHash() { >>>>> return new Random().nextInt() + ""; >>>>> } >>>>> } >>>>> ==== >>>>> >>>>> here is WEB-INF/web.xml: >>>>> >>>>> ==== >>>>> <web-app version="3.0" 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/web-app_3_0.xsd"> >>>>> <display-name>Archetype Created Web Application</display-name> >>>>> <listener> >>>>> >>>>> <listener-class>org.apache.webbeans.servlet.WebBeansConfigurationListener</listener-class> >>>>> </listener> >>>>> <resource-env-ref> >>>>> <resource-env-ref-name>BeanManager</resource-env-ref-name> >>>>> >>>>> <resource-env-ref-type>javax.enterprise.inject.spi.BeanManager</resource-env-ref-type> >>>>> </resource-env-ref> >>>>> </web-app> >>>>> ==== >>>>> >>>>> libs in WEB-INF/libs: >>>>> >>>>> openwebbeans-ee-common-1.2.0.jar >>>>> openwebbeans-el22-1.2.0.jar >>>>> openwebbeans-impl-1.2.0.jar >>>>> openwebbeans-resource-1.2.0.jar >>>>> openwebbeans-spi-1.2.0.jar >>>>> openwebbeans-tomcat7-1.2.0.jar >>>>> openwebbeans-web-1.2.0.jar >>>>> xbean-asm-shaded-3.13.jar >>>>> xbean-finder-shaded-3.13.jar >>>>> >>>>> The first question is about CDI implementation library. >>>>> If I try to deploy webapp as it is, the Tomcat will fail with next >>>>> exception: java.lang.NoClassDefFoundError: >>>>> javax/enterprise/context/spi/Contextual >>>>> I couldn't find OWB library which provides such class. I only >>>>> grabbed javaee-api-6.0-5-tomcat.jar from TomEE and placed in under Tomcat >>>>> 7 >>>>> lib/ folder. >>>>> What is a proper way to solve this problem? Where should I get >>>>> javax.enterprise.context.* library? >>>>> >>>>> The second question is about CDI itself. >>>>> After successful deploying (with javaee-api-6.0-5-tomcat.jar in lib/) >>>>> I accessed my servlet by http://localhost:8080/testproject/test and >>>>> got this responce: >>>>> ==== >>>>> >>>>> null >>>>> s2: 1064451662 >>>>> >>>>> ==== >>>>> >>>>> Why WebBeansContext.currentInstance().get(MyService.class) returns a >>>>> proper instance of MyService class and fails to inject it into private >>>>> @Inject MyService s? >>>>> >>>>> >>> >
