【问题标题】:what would be java.naming.provider.url for tomcattomcat 的 java.naming.provider.url 是什么
【发布时间】:2011-03-16 12:06:24
【问题描述】:

我正在尝试使用 Jndi 从 tomcat 服务器获取数据库连接。在那种情况下,如果是 tomcat,我的 java.naming.provider.url 会是什么??

【问题讨论】:

    标签: tomcat


    【解决方案1】:

    这个问题不是很清楚。根据 JNDI documentation,url 属性以 rmi://server:port 格式指定注册表的位置。因此,至少当您最初为在注册表中注册的对象的绑定创建命名上下文时,您需要传入注册表的位置。您可以找到示例代码here

    // select the registry service provider as the initial context
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.rmi.registry.RegistryContextFactory");
    
    // specify where the registry is running
    env.put(Context.PROVIDER_URL, "rmi://server:1099");
    
    // create an initial context that accesses the registry
    Context ctx = new InitialContext(env);
    
    // now, the names stored in registry can be listed
    NamingEnumeration enum = ctx.list("");
    

    【讨论】:

      猜你喜欢
      • 2011-10-30
      • 1970-01-01
      • 2011-09-03
      • 2013-01-30
      • 2014-03-19
      • 2016-02-09
      • 1970-01-01
      • 2012-01-21
      • 2012-05-08
      相关资源
      最近更新 更多