0

I have been trying to use JNDI to store my own predefined objects with no success. I can get the jdbc object from the InitialContext and gain access to the connection object as shown below

        Class.forName("com.mysql.jdbc.Driver");
      InitialContext context = new InitialContext();
    DataSource dataSource = (DataSource) context
     .lookup("jdbc/DataSource");

Now i need to know how to add my own objects to the jndi directory. Also please can you explain the architecture of jndi service

4

1 回答 1

0

我需要知道如何将我自己的对象添加到 jndi 目录。

如果您使用的是 Tomcat,请将它们定义为 Tomcat context.xml 中的命名资源,或者在任何 servlet 容器中定义它们的等价物。如果您打算在运行时执行此操作,则不能,那不是它的用途。

另外请你解释一下jndi服务的架构

StackOverflow 的问题太宽泛了。试试JNDI 教程

于 2012-07-23T11:02:33.997 回答