openwebbeans-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Romain Manni-Bucau <rmannibu...@gmail.com>
Subject Re: OWB on Tomcat 7
Date Sat, 09 Nov 2013 12:08:02 GMT
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" <aljesco@gmail.com> 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 <rmannibucau@gmail.com>
>
>> 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" <aljesco@gmail.com> 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?
>>>
>>>
>

Mime
View raw message