【问题标题】:javax.naming.NameNotFoundException on Context lookup Java上下文查找 Java 上的 javax.naming.NameNotFoundException
【发布时间】:2018-06-21 07:19:32
【问题描述】:

我正在使用一个 Payara 应用程序服务器,我在该服务器上定义了一个连接池,以便在我的应用程序中查找它。从应用服务器到数据库的 ping 正常。

在我的 domain.xml 数据库资源配置如下:

<jdbc-resource pool-name="MasterPool" jndi-name="jdbc/master"></jdbc-resource>
    <jdbc-connection-pool datasource-classname="org.apache.derby.jdbc.ClientDataSource40" name="MasterPool" res-type="javax.sql.DataSource">
      ...
    </jdbc-connection-pool>

Context的设置是在servlet init方法上进行的。

public void init() throws ServletException {

        Context env = null;
        Hashtable ht = new Hashtable();
        ht.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.fscontext.RefFSContextFactory");
        try {
            env = new InitialContext(ht);
            pool = (DataSource) env.lookup("master");
            System.out.println("Data source found");
        }
        catch(NamingException ne) {
            throw new ServletException(ne);
        }


    }

您能否对消息提供一些见解:

javax.servlet.ServletException: javax.naming.NameNotFoundException: master

我尝试在 jdbc/master 和 java:/comp/env/jdbc/master 之后进行查找

问候,

【问题讨论】:

  • 在 WEB-INF 中创建 glassfish-web.xml jdbc/masterjdbc/master-name>

标签: java datasource jndi java-ee-8


【解决方案1】:

确保您在 META-INF/context.xml 中有以下行

<Resource auth="Container" 
      driverClassName="com.mysql.jdbc.Driver" 
         ......
      name="master" // this line is important      
        .......    
/>

【讨论】:

  • 我已将以下条目添加到 web.xml DB Connectionjdbc/masterjavax.sql.DataSource容器
  • 我仍然收到 NameNotfoundException
  • 是 META-INF/context.xml,而不是 web.xml
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-08-19
  • 2013-05-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-04-23
  • 1970-01-01
相关资源
最近更新 更多