cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with injection

Former Member
0 Kudos

I have a simple test servlet,

public class TestAjaxServlet extends MyAjaxServlet {
	 @EJB private SomeBean sb;
  ..... 
  .....
}

Problem is, SomeBean instance is not injected and I get the following error in server's trace file.

System.err##System.err#Administrator#15#####Thread[RMI/IIOP Worker [3],5,Dedicated_Application_Thread]##0#0#Error##Plain###Warning: validation was turned on but an org.xml.sax.ErrorHandler was not set, which is probably not what is desired.  Parser will use a default ErrorHandler to print the first 10  errors.  Please call the setErrorHandler method to fix this.#
System.err##System.err#Administrator#15#####Thread[RMI/IIOP Worker [3],5,Dedicated_Application_Thread]##0#0#Error##Plain###Error: URI = "null", Line = "2", : Document is invalid: no grammar found. #
System.err##System.err#Administrator#15#####Thread[RMI/IIOP Worker [3],5,Dedicated_Application_Thread]##0#0#Error##Plain###Error: URI = "null", Line = "2", : Document root element "ejb-j2ee-engine", must match DOCTYPE root "null". #

When I change my servlet to extend HttpServlet, SomeBean value is injected and it works fine.

 public class TestAjaxServlet extends HttpServlet {
	 @EJB private SomeBean sb;
  ..... 
  .....
}

Does it have something to do with classloader ?

My ent App is packaged as follows:

 my_ent_app
              |__myAjaxServlet.jar
              |                     |__MyAjaxServlet.class
              |__SomeBean_EJB.jar
              |                     |__SomeBean.class
              |                     |__SomeBeanImpl.class
              |__myWebApp.war
                                    |__web-inf/classes/TestAjaxServlet.class
                                    |__web-inf/lib/myAjaxServlet.jar

Accepted Solutions (0)

Answers (1)

Answers (1)

Vlado
Advisor
Advisor
0 Kudos

Hi Vijaysarathi,

The traces above are actually emitted during deployment by the JAXP parser, don't bother about that.

Two things come to my mind at first sight (though they are quite trivial but anyway, doesn't hurt to ask, I hope):

1) What are the versions of your web.xml and application.xml (if any)? They should be 2.5 and 5, respectively, in order annotations to be processed and injections to be performed.

(This is most probably OK since you mention that it works when changing to HttpServlet.)

2) Does MyAjaxServlet extend HttpServlet and is it declared as servlet in the web.xml?

Best regards,

Vladimir

Former Member
0 Kudos

Hi Vladimir,

1) My web.xml is version 2.5 and

I donot have an application.xml, instead I have an application-j2ee-engine.xml and it contains:

 <?xml version="1.0" encoding="UTF-8"?>
<application-j2ee-engine xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="application-j2ee-engine.xsd">
</application-j2ee-engine>

2)Yes MyAjaxServlet extend HttpServlet. It is not declared as servlet in web.xml, instead I declared it's sub-class TestAjaxServlet as a servlet in web.xml

Note that my servlet's base class is packaged in a separate jar, my EJB is packaged in a separate jar and the test servlet is in a separate war file. I have added all these as dependencies in my Enterprise Application. Though my servlet is getting invoked, web container is unable to inject value when my servlet extends a class that is part of a different jar.

Thanks,

Vijaysarathi.

Vlado
Advisor
Advisor
0 Kudos

Hi Vijaysarathi,

Have you tried to put the servlet's base class in the WAR file alongside the test servlet and remove myAjaxServlet.jar from the application? My guess is that the behavior will be the same. It does not seem like a problem with the different jars, but rather with inheritance. Anyway, just give it a try, maybe I'm just too pessimistic...

Best regards,

Vladimir