Weblogic 10.3.5 & EJB 3 JNDI names

会有一股神秘感。 提交于 2020-01-02 19:56:16

问题


Could someone tell me where I can find infos on the default JNDI naming for EJB 3 ?

Does Weblogic use portable JNDI names like Glassfish?

Can I find (like for Glassfish) a trace of EJB deployment with JNDI names used?

For example :

  • an interface (Service) with only @Remote
  • a bean (ServiceImpl) with only @Stateless implementing the interface
  • everything packaged in an .ear file (service-application-1.0)

When deploying on Weblogic the only JNDI reference I see is:

service-application-1.0service-application-1.0_jarServiceImpl_Home

but I can't use that name with a context lookup. If I do

Service myService = (Service) context.lookup("service-application-1.0service-application-1.0_jarServiceImpl_Home");

it gives me

Exception in thread "main" java.lang.ClassCastException: weblogic.ejb.container.internal.StatelessEJBHomeImpl_1035_WLStub cannot be cast to com.tuto.Service
at com.tuto.TestEjb.main(TestEjb.java:24)

PS. With Glassfish it gives me

Portable jndi names for .... : java:global/service-application-1.0/service-application-ejb-1.0/ServiceImpl

And

Service myService = (Service) context.lookup("java:global/service-application-1.0/service-application-ejb-1.0/ServiceImpl");

is working.


回答1:


Unfortunately, EJB 3.0 does not specify a standard JNDI naming and leave it up to the server vendor. You are right by quoting WL documentation about mappedName: "If you specify this attribute, the stateless session bean may not be portable". The drawback of mappedName attribute is that the global JNDI name will be default to mappedName#FullyQualifiedRemoteInterface. Since mappedName is an annotation within the source code, it makes your code non-portable. The preferred way is to keep vendor-specific behavior in vendor specific deployment descriptors, such as weblogic-ejb-jar.xml. This way, you also have the choice of specifying your own custom JNDI name without the predetermined format as mappedName#FullyQualifiedRemoteInterface.

EJB 3.1 made some efforts to standardize JNDI names at global,application, and module levels. Please see http://docs.oracle.com/cd/E19798-01/821-1841/girgn/index.html




回答2:


You can try context.lookup("ServiveImpl#com.Service");, where ServiveImpl is the mapped name for bean & after # it should be fully qualified interface name.



来源:https://stackoverflow.com/questions/14872141/weblogic-10-3-5-ejb-3-jndi-names

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!