【发布时间】:2019-03-05 12:10:58
【问题描述】:
我正在尝试在 WebSphere Application Server Liberty 上使用配置为 JNDI 的数据源,但出现以下错误:
javax.naming.NameNotFoundException: java:comp/env/jdbc/myapp/master
Websphere 应用服务器中数据源的配置为:
<dataSource commitOrRollbackOnCleanup="commit" id="jdbc/myapp/master" jdbcDriverRef="ojdbc7" jndiName="jdbc/myapp/master">
<properties.oracle URL="jdbc:oracle:thin:@127.0.0.1:1521:xe" oracleRACXARecoveryDelay="0" password="xxxxxxxx" user="app_master">
</properties.oracle>
<connectionManager maxPoolSize="50"/>
</dataSource>
通过 servlet (jndi=jdbc/myapp/master) 中的此代码建立与数据库的连接:
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
DataSource ds = (DataSource) envCtx.lookup(jndi);
setConnection(ds.getConnection());
System.out.println(getConnection().toString() );
我做错了什么?
【问题讨论】:
标签: java datasource jndi websphere-liberty