Flyhard
Flyhard

Reputation: 554

How to correctly reference annotated EJB3 beans from JNDI in WAR-project

We have a multimodule Java EE 5 project running on Weblogic 10.3.x. One module has the EJBs and our batch processor is running from the web-module. Since we don't have CDI in JavaEE5, we have to do a JNDI-lookup on the EJBs. The EJBs are defined with @Stateless on the class and @Remote on the interface.

I have succeeded accessing the EJBs by looking the following string:

ejb/batchService#com.example.service.batch.ejb.BatchServiceRemote

However, I belive this is highly platformdependent, and I suspect I should have put something inside the web.xml and probably into the weblogic.xml at least in the web-module - maybe even in the EJB module...

Could anyone enlighten me how to do this propperly? Or is this the best way available?

Upvotes: 0

Views: 722

Answers (2)

Brett Kail
Brett Kail

Reputation: 33936

Prior to EJB 3.1 / EE 6, there are no standardized lookup strings for EJBs. Since they're not standardized, hard-coding the actual binding name of the EJB does make your project product-specific.

The best solution is to create another level of indirection: declare an <ejb-local-ref> in web.xml (or as @EJB/@EJBs on a servlet or other component class), and then use java:comp/env/xyz to lookup the ref. Then, use platform-specific bindings for the EJB ref.

Upvotes: 0

Ilya
Ilya

Reputation: 29673

JNDI format of local bean is

java:comp/env/BeanClassName  

JNDI format for remote bean is

mappedName#com.package.BeanClassName  

for

@Stateless(mappedName = "mappedName")
public class BeanClassName  {  

PS. This format supported by WebLogic 10.3. Behaviour of another application servers may be differentю

Upvotes: 1

Related Questions