Glassfish和TomEE之间的差异JNDI配置?

时间:2014-11-20 06:09:25

标签: glassfish jndi apache-tomee

我们希望将旧应用程序从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 DataSource引用," jms"对于JMS连接工厂," mail"对于JavaMail连接工厂," url"用于URL连接工厂。

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

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

1 个答案:

答案 0 :(得分:1)

Tomcat(然后是TomEE)不是为了在运行时更改JNDI而设计的。简单地说它最好不是使用这种模式而是使用上下文资源。注入你想要的资源,这是你改变的资源,而不是JNDI(这看起来更具影响力)

相关问题