4 Replies Latest reply on Oct 13, 2008 3:33 AM by jaikiran pai

    Injecting an EJB into a Servlet

    Javid Jamae Newbie

      I'm trying to inject an EJB into a Servlet in JBoss 5 CR2. I have an ear called video.ear. The ear has a video.war, video.jar, and video.har in it (though the har should be irrelevant).

      The binding

      Here is my Servlet Code:

      public class VideoServlet extends HttpServlet {
       @EJB(mappedName="video/VideoServiceImpl/local")
       private VideoService videoService;
      


      I'm not sure if I have to put the "mappedName" on there, but I tried it without and it didn't work.

      My web.xml has the correct schema:
      <web-app 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_2_5.xsd"
       version="2.5">
      


      I noticed I had this in the log
      22:46:34,065 WARN [MappedReferenceMetaDataResolverDeployer] Unresolved references exist in JBossWebMetaData:[video.war#web-app:AnnotatedEJBReferenceMetaData{name=videoService,ejb-ref-type=null,link=null,ignore-dependecy=false,mapped/jndi-name=video/VideoServiceImpl/local,resolved-jndi-name=null,beanInterface=interface
       com.manning.jbia.hibernateinjection.VideoService}]
      .
      .
      .
      22:46:42,237 INFO [TomcatDeployment] deploy, ctxPath=/video, vfsUrl=video.ear/video.war
      


      When I try to access the servlet, I get:
      22:49:54,654 INFO [[/video]] Marking servlet Video as unavailable
      22:49:54,654 ERROR [[Video]] Allocate exception for servlet Video
      javax.naming.NameNotFoundException: video not bound
       at org.jnp.server.NamingServer.getBinding(NamingServer.java:564)
       at org.jnp.server.NamingServer.getBinding(NamingServer.java:572)
       at org.jnp.server.NamingServer.getObject(NamingServer.java:578)
       at org.jnp.server.NamingServer.lookup(NamingServer.java:288)
       at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:669)
       at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:629)
       at javax.naming.InitialContext.lookup(InitialContext.java:351)
       at org.jnp.interfaces.NamingContext.resolveLink(NamingContext.java:1251)
      
       at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:760)
       at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:629)
       at org.jboss.ejb3.JndiUtil.lookup(JndiUtil.java:44)
       at org.jboss.injection.JndiPropertyInjector.lookup(JndiPropertyInjector.
      java:75)
       at org.jboss.injection.JndiPropertyInjector.inject(JndiPropertyInjector.
      java:99)
       at org.jboss.web.tomcat.service.TomcatInjectionContainer.processInjector
      s(TomcatInjectionContainer.java:361)
       at org.jboss.web.tomcat.service.TomcatInjectionContainer.newInstance(Tom
      catInjectionContainer.java:244)
       at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.
      java:1006)
       at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.jav
      a:777)
       at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
      alve.java:129)
       at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
      alve.java:191)
       at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(Securit
      yAssociationValve.java:189)
       at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValv
      e.java:91)
       at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invok
      e(SecurityContextEstablishmentValve.java:92)
       at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
      ava:127)
       at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
      ava:102)
       at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedC
      onnectionValve.java:157)
       at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
      ve.java:109)
       at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
      a:325)
       at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
      :828)
       at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proce
      ss(Http11Protocol.java:601)
       at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:44
      7)
       at java.lang.Thread.run(Thread.java:595)
      


      Any ideas?