You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@geronimo.apache.org by Krishnakumar B <ww...@gmail.com> on 2006/12/12 09:14:31 UTC

Using @Resource in servlet

hi,

I am trying a sample application that uses @Resource to get a
reference to the Datasource deployed on the server ( SystemDatasource
).

Server Version : 2.0-SNAPSHOT-Tomcat6-JEE5

I have tried
@Resource  javax.sql.DataSource SystemDatasource &

@Resource (mappedName="java:comp/env/jdbc/SystemDatasource")
javax.sql.DataSource SystemDatasource;

Both give errrors. I think the usage i am trying is not correct.

Dec 12, 2006 1:36:15 PM org.apache.catalina.core.ApplicationContext log
SEVERE: StandardWrapper.Throwable
java.lang.NullPointerException
        at com.test.servlet.SampleServlet.init(SamleServlet.java:80)
        at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.
java:1161)
        at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.jav
a:806)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:133)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:175)
        at org.apache.geronimo.tomcat.valve.DefaultSubjectValve.invoke(DefaultSu
bjectValve.java:56)
        at org.apache.geronimo.tomcat.GeronimoStandardContext$SystemMethodValve.
invoke(GeronimoStandardContext.java:325)
        at org.apache.geronimo.tomcat.valve.GeronimoBeforeAfterValve.invoke(Gero
nimoBeforeAfterValve.java:47)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:128)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
ava:105)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
ve.java:109)
        at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:
542)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
a:212)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
:818)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proce
ss(Http11Protocol.java:624)
        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:44
5)
        at java.lang.Thread.run(Thread.java:595)

Any pointers as to how to provide the @Resource reference.

Regards
Krish

Re: Using @Resource in servlet

Posted by Paul McMahan <pa...@gmail.com>.
Not all of the annotations that can appear in a webapp have a 1:1
correspondence with the DD but some do. The rationale behind merging
the annotation into the DD is to support the management APIs which can
ask for a deployed object's DD which should include its annotations.
This was discussed a while back on dev http://tinyurl.com/y968n9
Merging the annotations before deployment seemed like an easy way to
provide that but that may not work.

But the more I think about it the more I think it makes sense to
implement support for @Resource (at least) in the naming builder as
David suggested.   We should fully hash out this discussion on dev.
(as I type this message my email notifier just showed me that
discussion has already started :-)

Best wishes,
Paul

On 12/12/06, Sachin Patel <sp...@gmail.com> wrote:
> Thats assuming there is a 1-1 mapping for all annotations to dd xml
> elements.  Do you know if that is the case?
>
>
> On Dec 12, 2006, at 9:33 AM, Paul McMahan wrote:
>
>
> My
>
> very early thoughts were that the annotations could be merged into the
>
> deployment descriptor before the builder processes it.
>
> -sachin
>
>

Re: Using @Resource in servlet

Posted by Sachin Patel <sp...@gmail.com>.
Thats assuming there is a 1-1 mapping for all annotations to dd xml  
elements.  Do you know if that is the case?

On Dec 12, 2006, at 9:33 AM, Paul McMahan wrote:

> My
> very early thoughts were that the annotations could be merged into the
> deployment descriptor before the builder processes it.


-sachin



Re: Using @Resource in servlet

Posted by Paul McMahan <pa...@gmail.com>.
Correct - annotations are not implemented in the tomcat6-jee5 assembly
yet.  I am planning to start looking at that after the holidays.  My
very early thoughts were that the annotations could be merged into the
deployment descriptor before the builder processes it.  But at this
point I've spent very little time investigating that approach.  I
think ideally Geronimo could have one approach that works across all
the Java EE5 components that support annotations.

Best wishes,
Paul

On 12/12/06, David Jencks <da...@yahoo.com> wrote:
> This is probably not implemented yet.  It certainly doesn't work with
> jetty6 yet.
>
> We're going to need to scan the code and hook the output of the
> annotation scanner into the naming builder framework to get the stuff
> needed bound in jndi, and then do something to inject these
> resources.  It's possible that both jetty and tomcat have some way of
> going from jndi to injection and they might have scanners of some
> sort but I don't see how they can hook into our naming builders
> without us writing a bunch of code.
>
> thanks
> david jencks
>
> On Dec 12, 2006, at 12:14 AM, Krishnakumar B wrote:
>
> > hi,
> >
> > I am trying a sample application that uses @Resource to get a
> > reference to the Datasource deployed on the server ( SystemDatasource
> > ).
> >
> > Server Version : 2.0-SNAPSHOT-Tomcat6-JEE5
> >
> > I have tried
> > @Resource  javax.sql.DataSource SystemDatasource &
> >
> > @Resource (mappedName="java:comp/env/jdbc/SystemDatasource")
> > javax.sql.DataSource SystemDatasource;
> >
> > Both give errrors. I think the usage i am trying is not correct.
> >
> > Dec 12, 2006 1:36:15 PM org.apache.catalina.core.ApplicationContext
> > log
> > SEVERE: StandardWrapper.Throwable
> > java.lang.NullPointerException
> >        at com.test.servlet.SampleServlet.init(SamleServlet.java:80)
> >        at org.apache.catalina.core.StandardWrapper.loadServlet
> > (StandardWrapper.
> > java:1161)
> >        at org.apache.catalina.core.StandardWrapper.allocate
> > (StandardWrapper.jav
> > a:806)
> >        at org.apache.catalina.core.StandardWrapperValve.invoke
> > (StandardWrapperV
> > alve.java:133)
> >        at org.apache.catalina.core.StandardContextValve.invoke
> > (StandardContextV
> > alve.java:175)
> >        at
> > org.apache.geronimo.tomcat.valve.DefaultSubjectValve.invoke(DefaultSu
> > bjectValve.java:56)
> >        at org.apache.geronimo.tomcat.GeronimoStandardContext
> > $SystemMethodValve.
> > invoke(GeronimoStandardContext.java:325)
> >        at
> > org.apache.geronimo.tomcat.valve.GeronimoBeforeAfterValve.invoke(Gero
> > nimoBeforeAfterValve.java:47)
> >        at org.apache.catalina.core.StandardHostValve.invoke
> > (StandardHostValve.j
> > ava:128)
> >        at org.apache.catalina.valves.ErrorReportValve.invoke
> > (ErrorReportValve.j
> > ava:105)
> >        at org.apache.catalina.core.StandardEngineValve.invoke
> > (StandardEngineVal
> > ve.java:109)
> >        at org.apache.catalina.valves.AccessLogValve.invoke
> > (AccessLogValve.java:
> > 542)
> >        at org.apache.catalina.connector.CoyoteAdapter.service
> > (CoyoteAdapter.jav
> > a:212)
> >        at org.apache.coyote.http11.Http11Processor.process
> > (Http11Processor.java
> > :818)
> >        at org.apache.coyote.http11.Http11Protocol
> > $Http11ConnectionHandler.proce
> > ss(Http11Protocol.java:624)
> >        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run
> > (JIoEndpoint.java:44
> > 5)
> >        at java.lang.Thread.run(Thread.java:595)
> >
> > Any pointers as to how to provide the @Resource reference.
> >
> > Regards
> > Krish
>
>

Re: Using @Resource in servlet

Posted by David Jencks <da...@yahoo.com>.
This is probably not implemented yet.  It certainly doesn't work with  
jetty6 yet.

We're going to need to scan the code and hook the output of the  
annotation scanner into the naming builder framework to get the stuff  
needed bound in jndi, and then do something to inject these  
resources.  It's possible that both jetty and tomcat have some way of  
going from jndi to injection and they might have scanners of some  
sort but I don't see how they can hook into our naming builders  
without us writing a bunch of code.

thanks
david jencks

On Dec 12, 2006, at 12:14 AM, Krishnakumar B wrote:

> hi,
>
> I am trying a sample application that uses @Resource to get a
> reference to the Datasource deployed on the server ( SystemDatasource
> ).
>
> Server Version : 2.0-SNAPSHOT-Tomcat6-JEE5
>
> I have tried
> @Resource  javax.sql.DataSource SystemDatasource &
>
> @Resource (mappedName="java:comp/env/jdbc/SystemDatasource")
> javax.sql.DataSource SystemDatasource;
>
> Both give errrors. I think the usage i am trying is not correct.
>
> Dec 12, 2006 1:36:15 PM org.apache.catalina.core.ApplicationContext  
> log
> SEVERE: StandardWrapper.Throwable
> java.lang.NullPointerException
>        at com.test.servlet.SampleServlet.init(SamleServlet.java:80)
>        at org.apache.catalina.core.StandardWrapper.loadServlet 
> (StandardWrapper.
> java:1161)
>        at org.apache.catalina.core.StandardWrapper.allocate 
> (StandardWrapper.jav
> a:806)
>        at org.apache.catalina.core.StandardWrapperValve.invoke 
> (StandardWrapperV
> alve.java:133)
>        at org.apache.catalina.core.StandardContextValve.invoke 
> (StandardContextV
> alve.java:175)
>        at  
> org.apache.geronimo.tomcat.valve.DefaultSubjectValve.invoke(DefaultSu
> bjectValve.java:56)
>        at org.apache.geronimo.tomcat.GeronimoStandardContext 
> $SystemMethodValve.
> invoke(GeronimoStandardContext.java:325)
>        at  
> org.apache.geronimo.tomcat.valve.GeronimoBeforeAfterValve.invoke(Gero
> nimoBeforeAfterValve.java:47)
>        at org.apache.catalina.core.StandardHostValve.invoke 
> (StandardHostValve.j
> ava:128)
>        at org.apache.catalina.valves.ErrorReportValve.invoke 
> (ErrorReportValve.j
> ava:105)
>        at org.apache.catalina.core.StandardEngineValve.invoke 
> (StandardEngineVal
> ve.java:109)
>        at org.apache.catalina.valves.AccessLogValve.invoke 
> (AccessLogValve.java:
> 542)
>        at org.apache.catalina.connector.CoyoteAdapter.service 
> (CoyoteAdapter.jav
> a:212)
>        at org.apache.coyote.http11.Http11Processor.process 
> (Http11Processor.java
> :818)
>        at org.apache.coyote.http11.Http11Protocol 
> $Http11ConnectionHandler.proce
> ss(Http11Protocol.java:624)
>        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run 
> (JIoEndpoint.java:44
> 5)
>        at java.lang.Thread.run(Thread.java:595)
>
> Any pointers as to how to provide the @Resource reference.
>
> Regards
> Krish