You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by Maxime Thieu <ma...@gmail.com> on 2008/12/19 10:03:06 UTC
EJB Annotation does not work in AbstractServlet
Hello,
I am using OpenEJB 3.1 in Tomcat.
I use the Annotation @EJB in my Servlet in order to obtain my EJB and it
works well.
But If I use the Annotation @EJB in an abstract Servlet (which is the
superclass of all my Servlets), it does'nt work : it seams that the EJB
Annotation is not "interpreted" by openEJB.
Is this normal ? Is there any way for referencing EJB in abstract Servlet ?
Thanks in advance,
Maxime
Example :
public abstract class AbstractTestServlet extends HttpServlet {
@EJB
protected MyEJB myEJB;
protected void testEJB() {
myEJB.test();
}
}
public class TestServlet extends AbstractTestServlet {
@EJB
protected MyEJB myEJB2;
...
protected void testMyEJB() {
myEJB2.test(); // this works
testEJB(); // this doesn't work : NPE
myEJB.test(); // this doesn't work : NPE (myEJB is null)
}
}
--
View this message in context: http://www.nabble.com/EJB-Annotation-does-not-work-in-AbstractServlet-tp21087942p21087942.html
Sent from the OpenEJB User mailing list archive at Nabble.com.
Re: EJB Annotation does not work in AbstractServlet
Posted by Maxime Thieu <ma...@gmail.com>.
Thanks for your response and for opening this Jira.
It will be great to have this feature. Actually, my abstract Servlet have an
abstract method wich return an EJB, and all my other servlets (extending the
abstract servlet) define an EJB just for returning it to the super class ...
Any idea of what version of OpenEJB should have this feature ?
Maxime
David Blevins wrote:
>
>
> On Dec 19, 2008, at 1:03 AM, Maxime Thieu wrote:
>
>>
>> Hello,
>>
>> I am using OpenEJB 3.1 in Tomcat.
>>
>> I use the Annotation @EJB in my Servlet in order to obtain my EJB
>> and it
>> works well.
>>
>> But If I use the Annotation @EJB in an abstract Servlet (which is the
>> superclass of all my Servlets), it does'nt work : it seams that the
>> EJB
>> Annotation is not "interpreted" by openEJB.
>>
>> Is this normal ? Is there any way for referencing EJB in abstract
>> Servlet ?
>
> We could get this to work, but we'd have to replace the annotation
> processor in Tomcat. That isn't really a big deal and would be an
> easy feature to add. We simply error on the conservative side when it
> comes to replacing parts of Tomcat in the Tomcat/OpenEJB integration
> (we want Tomcat to still feel like Tomcat), usually holding off till
> someone requests a feature that requires it. This would be one of
> those features.
>
> The Tomcat annotation processor is pretty decent in that it looks for
> the basic annotations then blindly looks up from JNDI and injects what
> it finds -- this allows us to expand it to support things that Tomcat
> doesn't normally support. But there two things it will not do: look
> for annotations in super classes (as you notice); do xml-only injection.
>
> Added a jira for it:
>
> https://issues.apache.org/jira/browse/OPENEJB-979
>
> -David
>
>
>
--
View this message in context: http://www.nabble.com/EJB-Annotation-does-not-work-in-AbstractServlet-tp21087942p21125847.html
Sent from the OpenEJB User mailing list archive at Nabble.com.
Re: EJB Annotation does not work in AbstractServlet
Posted by David Blevins <da...@visi.com>.
On Dec 19, 2008, at 1:03 AM, Maxime Thieu wrote:
>
> Hello,
>
> I am using OpenEJB 3.1 in Tomcat.
>
> I use the Annotation @EJB in my Servlet in order to obtain my EJB
> and it
> works well.
>
> But If I use the Annotation @EJB in an abstract Servlet (which is the
> superclass of all my Servlets), it does'nt work : it seams that the
> EJB
> Annotation is not "interpreted" by openEJB.
>
> Is this normal ? Is there any way for referencing EJB in abstract
> Servlet ?
We could get this to work, but we'd have to replace the annotation
processor in Tomcat. That isn't really a big deal and would be an
easy feature to add. We simply error on the conservative side when it
comes to replacing parts of Tomcat in the Tomcat/OpenEJB integration
(we want Tomcat to still feel like Tomcat), usually holding off till
someone requests a feature that requires it. This would be one of
those features.
The Tomcat annotation processor is pretty decent in that it looks for
the basic annotations then blindly looks up from JNDI and injects what
it finds -- this allows us to expand it to support things that Tomcat
doesn't normally support. But there two things it will not do: look
for annotations in super classes (as you notice); do xml-only injection.
Added a jira for it:
https://issues.apache.org/jira/browse/OPENEJB-979
-David