简体   繁体   中英

How to share EJB local interface across applications installed on the same WebSphere Application Server?

I'm having a problem with WebSphere Application Server 7. I have 2 applications installed on WAS A & B. B wants to use a local EJB interface of A's.

The module that contains the local EJB interface is part of A's EAR.

What I tried doing was including a reference to the module in my deployment of B. The problem I found was that, while looking up the interface:

InitialContext ic = new InitialContext();
//succeeds
Object obj = ic.lookup("ejblocal:sample.MyEJBLocal");
//fails with ClassCastException
MyEJBLocal localBean = (MyEJBLocal) obj;

The program crashes because the Interface has random letters prefixed to the name of the class, eg

Cannot cast type SL07SMyEJBLocal to MyEJBLocal these types are incompatible.

I tried playing around with WAS & I was able to get the cast to succeed by changing the class loader settings for the server from multiple to single.

Q - I don't really like the idea of having one class loader for all the applications on my server - is there another way to get the EJB local interface to be shared across application A & B?

See the "Local client views" section of the EJB modules module of the InfoCenter (I've linked to the 8.5 InfoCenter, but the advice applies to all versions). Basically, in order to share a local interface, you must ensure that both applications have a view of the same class. The most common approach is to use a server-associated shared library. Note carefully the other caveats of sharing a local EJB across applications.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM