关于 jakarta ee:mappedName 跨应用服务器总是一样的?

The mappedName is always the same across application servers?

我有一个具有一些属性的无状态 bean:

  • 这是一个 EJB3
  • 类 AddressFacade
  • 实现 AddressFacadeRemote
  • 它在 ejb-jar (MyJAR.jar) 中
  • 它在 EAR (MyEAR) 中。
  • 我的应用服务器 (Weblogic) 生成了这个名称 (jndiName/mappedName):

    1
    MyEARMyJAR_jarAddressFacade_AddressFacadeRemote

    我不能使用注入,所以我会用这个名字进行查找。

    问题是:如果我保持相同的 EAR、JAR、类和接口名称,这个名称总是相同的吗?或者它可以从应用服务器改变?


    The question is: this name always will be the same if I maintain the same EAR,JAR,Class and interface name? Or it can change from application servers?

    JNDI 名称在 Java EE 5 中没有标准化,并且会从一个应用服务器更改为另一个。 Adam Bien 写了一篇很好的文章来说明这一点:

    EJB 3 Portability Issue: why JNDI names are not standardized?

    As I mentioned in my previous post,
    the portability of Java EE 5
    applications is much better, than in
    the old J2EE 1.4 world. I found one
    issue, which causes some effort - the
    lack of defined and unified
    JNDI-Naming and addressing. The
    glassfish applicationsserver uses the
    fully qualified name of the
    remote business interface as default.
    The JBoss appserver uses the name of
    the EJB with the"/remote" ending. So
    the following Session Bean:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    package com.abien;

    @Stateless
    public class HelloWorldBean implements HelloWorld {

        public String sayHello(String hello){
            return"Echo from server:";
        }
    }

    can be found with JBoss (with EJB3
    support) using the following
    code-snippet:

    1
    2
    Context context = new InitialContext();
    HelloWorld helloWorld = (HelloWorld) context.lookup("myEarName/HelloWorldBean/remote");

    and Glassfish (v1 and v2), using the
    fully qualified name of the
    remote-business interface:

    1
    2
    Context context = new InitialContext();
    HelloWorld helloWorld = (HelloWorld) context.lookup(HelloWorld.class.getName());

    处理这个问题的一个不错的方法是使用 ServiceLocator 和"可插入"应用程序服务器特定的策略。看看 ServiceLocator、JNDI Naming Helper 和 Java EE 5。

    在 Java EE 6 中,事情得到了解决,我们终于有了可移植的全局 JNDI 名称。