我正在尝试在 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() );
我究竟做错了什么?