[jboss-user] [EJB 3.0] - Re: Why is injection not working in AS 4.0 and 4.2 (servlets

Zyborg do-not-reply at jboss.com
Wed Oct 17 12:41:37 EDT 2007


hi all!

my application is packed into a .ear file and gets deployed into a jboss 5 beta2.
i am trying to inject a EntityManager from a servlet without success ...
should my scenario work or is there something i misunderstood?
maybe its just a deployment failure - so i packaged my ear file note correctly?
i ran out of ideas ... please help!

the ear file structure looks like:

  | META-INF/
  |   |-- jboss-app.xml
  |   |-- application.xml
  | beans.jar
  |   |--META-INF/
  |        |--persistence.xml
  |   |--com/
  |        |--myapp/
  |              |--...
  | web.war
  |   |--WEB-INF/
  |         |-- classes/
  |         |-- lib/
  |         |--web.xml
  | 

jboss-app.xml:

  | <!DOCTYPE jboss-app
  |           PUBLIC "-//JBoss//DTD J2EE Application 1.4//EN"
  |           "http://www.jboss.org/j2ee/dtd/jboss-app_4_0.dtd">
  | <jboss-app>
  |   <loader-repository>
  |     com.myapp:loader=MyApp.ear
  |   </loader-repository>
  | </jboss-app>
  | 

application.xml:

  | <?xml version="1.0" encoding="UTF-8"?>
  | <application>
  |     <display-name>My Application Title</display-name>
  |     <description>My Application Title Description</description>
  | 
  |     <module>
  |       <ejb>beans.jar</ejb>
  |     </module>
  | 
  |     <module>
  |         <web>
  |             <web-uri>web.war</web-uri>
  |             <context-root>MyApp</context-root>
  |         </web>
  |     </module>
  | </application>
  | 

the injection code in the servlet looks like:

  | 	@PersistenceContext(unitName="MyUnit")
  | 	private EntityManager em;
  | 


On deployment i get following error:

  | java.lang.RuntimeException: @PersistenceContext(name='env/com.myapp.server.MyServiceImpl/em',unitName='MyUnit') on EJB: web.war failed to inject on field private javax.persistence.EntityManager com.myapp.server.MyServiceImpl.em Unable to find persistence unit: MyUnit for deployment: web.war
  |         at org.jboss.injection.PcEncInjector.inject(PcEncInjector.java:85)
  |         at org.jboss.web.tomcat.service.TomcatInjectionContainer.populateEnc(TomcatInjectionContainer.java:213)
  |         at org.jboss.web.tomcat.service.deployers.TomcatDeployment$EncListener.lifecycleEvent(TomcatDeployment.java:471)
  |         at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
  |         at org.apache.catalina.core.StandardContext.start(StandardContext.java:4356)
  |         at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:761)
  |         at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:741)
  |         at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:553)
  |         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  |         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
  |         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
  |         at java.lang.reflect.Method.invoke(Method.java:585)
  |         at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:297)
  |         at org.jboss.mx.server.RawDynamicInvoker.invoke(RawDynamicInvoker.java:164)
  |         at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:668)
  |         at org.apache.catalina.core.StandardContext.init(StandardContext.java:5312)
  |         at org.jboss.web.tomcat.service.deployers.TomcatDeployment.performDeployInternal(TomcatDeployment.java:298)
  |         at org.jboss.web.tomcat.service.deployers.TomcatDeployment.performDeploy(TomcatDeployment.java:138)
  |         at org.jboss.web.deployers.AbstractWarDeployment.start(AbstractWarDeployment.java:367)
  |         at org.jboss.web.deployers.WebModule.startModule(WebModule.java:104)
  |         at org.jboss.web.deployers.WebModule.start(WebModule.java:80)
  |         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  |         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
  |         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
  |         at java.lang.reflect.Method.invoke(Method.java:585)
  |         at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:157)
  |         at org.jboss.mx.server.Invocation.dispatch(Invocation.java:96)
  |         at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
  |         at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
  |         at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:668)
  |         at org.jboss.system.microcontainer.ServiceProxy.invoke(ServiceProxy.java:184)
  |         at $Proxy0.start(Unknown Source)
  | 

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4096190#4096190

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4096190



More information about the jboss-user mailing list