users@glassfish.java.net

Re: _at_EJB in further classes

From: Sahoo <Sahoo_at_Sun.COM>
Date: Fri, 21 Dec 2007 11:30:58 +0530

Injection is allowed in managed classes (e.g. Servlets, filters,
listeners, etc.). If Servant is just an ordinary class in your war file,
then @EJB is ignored resulting in NPE. This requirement is specified in
the Java EE platform spec.

Sahoo
Pawel R. wrote:
> Hi,
>
> I have a servlet:
> ...
> @EJB
> EJBServerCommunicatorLocalInterface server;
>
> protected void doGet(HttpServletRequest request, HttpServletResponse
> response) throws ServletException, IOException {
> Servant s = new Servant();
> // response.getWriter().write("<h1>" + s.test() + "</h1>");
> //ERROR
> response.getWriter().write("<h1>" + server.test() +
> "</h1>");
> }
> ...
>
> Why does the commented line causes:
> [#|2007-12-21T03:09:02.600+0100|SEVERE|sun-appserver9.1|javax.enterprise.sys
> tem.container.web|_ThreadID=22;_ThreadName=httpSSLWorkerThread-8080-1;_Reque
> stID=0d659ef1-1106-40e1-81a0-122c6371f3e4;|StandardWrapperValve[Test]:
> PWC1406: Servlet.service() for servlet Test threw exception
> java.lang.NullPointerException,
>
> when the Servant class looks like:
> ...
> @EJB
> EJBServerCommunicatorLocalInterface server;
>
> public String test() {
> return server.test();
> }
> ...
>
> Thanks in advance,
> Paweł R.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
>