Glassfish 4: how to set application or module name for JNDI

[亡魂溺海] 提交于 2019-12-08 16:49:44

问题


I use EJB inside OSGi bundles. And now when I need to get EJB I have long jndi, for example:

bean = (InterfaceName) ctx.lookup("java:global/longBundleName_version/OrganizationDirBean!and.plus.path.and.InterfaceName");

I want to change this part:

longBundleName_version

I mean, when I deploy bundle this part must be set from [glassfish-]application.xml or from [glassfish-]-ejb-jar.xml or from any other xml descriptor. I want jndi name for my ejb to be like:

java:global/newBundleNameWithoutVersion/etc

The problem that I can't find what I must set in these files. All variants I found in internet are not supported anymore and all I tried myself didn't work. Could you help me?

Please, don't offer mappedName as it can be used only(!) for remote beans. I do use beans which are at the same time both local and remote.

If someone is involved in glassfish development, could you at least point what bundles I must examine to find the question by myself? I will be very grateful.


回答1:


You should annotate your EJB like that:

@Remote(value = YourInterface.class)
@Stateless(mappedName = "java:global/fancy")

After that, GF logs says:

EJB5182:Glassfish-specific (Non-portable) JNDI names for EJB YourInterfaceImpl: [java:global/fancy, java:global/fancy!com.example.YourInterface]]]

And at least I was able to inject like:

<!-- language:java -->

@EJB(lookup="java:global/fancy")

So I think manual look up should also work.



来源:https://stackoverflow.com/questions/24150521/glassfish-4-how-to-set-application-or-module-name-for-jndi

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