Glassfish 4: how to set application or module name

2019-06-17 02:38发布

问题:

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.