开发者

Weblogic Ear deployment fails to inject entity manager

开发者 https://www.devze.com 2023-02-28 09:39 出处:网络
The issue I am currently experiencing is that my entityManager fails to be injected during the execution of a web application deployed within an ear.

The issue I am currently experiencing is that my entityManager fails to be injected during the execution of a web application deployed within an ear.

The ear is setup as follows:

/META-INF -application.xml (EJBJar + WAR)

-MANIFEST.MF

-weblogic-application.xml (currently just the default one that eclipse generates)

/APP-INF

-lib

-EJBClientJar (interfaces + pojos)

-other jars
 -classes   

EJBJar

/META-INF

-persistence.xml

/src

-Annotated classes

WAR

-Service classes

Classes are as follows:

DAO inside EJBJar

@Stateless(mappedName="AwesomeBean")
public class Awesome implements AwesomeRemote //AwesomeRemote in EJBClientJar
{     
   @PersistenceContext
   EntityManager em;   
}


public class AwesomeService   //Inside WAR
{  
    AwesomeRemote = context.lookup (Awesome.path.to.AwesomeRemote)  //Is found
}

The call stack is like this:

War -> EJBClientJar -> EJBJar

On the EJB jar the entity manager is null. Question being how do I ensure that the PersistenceContext gets injected? The JNDI lookup succeeds on the AwesomeRemote I开发者_如何学编程nterface. The Interface has no annotations on it.


It's probably due to the fact that you try to inject on POJO class, not on managed component. Could you try to mark it as @Stateless and public and check whether it works? For simple testing you can also add @WebService annotation and invoke your bean with SoapUI for example.


You should read about "packaging" part of ejb specifications.

This structure should be sufficient and work:

/
    /lib
        EJBClientJar (interfaces + pojos)
    /META-INF
        persistence.xml
        application.xml
    EJBJar.jar
    WAR.war

As some formatting was lost, I'm not sure about what wasn't right in yours.

If this still doesn't work, try removing the only tricky part from above: put all classes from EJBClientJar in root. You the just have the most simple EAR packaging possible, it just will work.

Also, if you don't use your session bean outside a web application, you could use @Local instead of @Remote .

0

精彩评论

暂无评论...
验证码 换一张
取 消