【问题标题】:Difference JNDI configuration between Glassfish and TomEE?Glassfish和TomEE之间的JNDI配置差异?
【发布时间】:2015-01-17 22:03:33
【问题描述】:

我们希望将旧应用程序从 Glassfish 迁移到 TomEE。我们遇到了一个关于 JNDI 的问题。

当我为 Glassfish 服务器 asadmin list-jndi-entries 运行 cmd 时,我得到了一些 JNDI 条目:

java:global: com.sun.enterprise.naming.impl.TransientContext
UserTransaction: com.sun.enterprise.transaction.TransactionNamingProxy$UserTransactionProxy
com: com.sun.enterprise.naming.impl.TransientContext
OURAPPSERVER-Q2: com.ourcompany.product.OurAppServer
com.sun.enterprise.container.common.spi.util.InjectionManager: com.sun.enterprise.container.common.impl.util.InjectionManagerImpl
ejb: com.sun.enterprise.naming.impl.TransientContext
jdbc: com.sun.enterprise.naming.impl.TransientContext
AppServer: com.sun.enterprise.naming.impl.TransientContext

如您所见,有 AppServer JNDI 条目。此条目是从我们的代码中手动绑定的。

        try {
            InitialContext context = new InitialContext();
            context.rebind("AppServer/facede", this);
        } catch (NamingException e) {
            e.printStackTrace();
            logger.severe("Unable to register the service facade bean, "
                    + "JPOS will not be able to access services");
        }

此代码在 TomEE 中不起作用。我收到一些错误,例如:

javax.naming.NameNotFoundException: Name [AppServer/facede] is not bound in this Context. Unable to find [AppServer].
    at org.apache.naming.NamingContext.bind(NamingContext.java:899)
    at org.apache.naming.NamingContext.rebind(NamingContext.java:225)

容器似乎找不到基于 AppServer 的上下文。

我不是 JNDI 的高手。然后我检查了一些文件。 java:comp/env/ 是基本的命名空间。 “jdbc”用于 DBCTM 数据源引用,“jms”用于 JMS 连接工厂,“mail”用于 JavaMail 连接工厂,“url”用于 URL 连接工厂。

我们不想对旧的应用程序代码进行太多更改。它没有使用 Glassfish 的任何特殊功能。我想知道如何以正确的方式定义 JNDI。

有没有人能告诉我为什么 Glassfish 可以使用 AppServer 作为命名空间,而 TomEE 却不能。

【问题讨论】:

    标签: glassfish jndi apache-tomee


    【解决方案1】:

    Tomcat(然后是 TomEE)并非旨在像它那样在运行时更改 JNDI。简单地说,最好不要使用这种模式,而是使用上下文资源。注入您想要的资源,这就是您更改的资源而不是 JNDI(这似乎更具影响力)

    【讨论】:

    • 你是对的。检查文档后,TomEE JNDI 上下文仅在运行时准备就绪。我必须在配置文件中创建一个标准的 JNDI 名称。
    猜你喜欢
    • 2011-07-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多