【发布时间】:2021-09-24 20:52:00
【问题描述】:
我将 jdk 11 与 Eclipse 2021 和 WAS Liberty 21.0.0.4 一起使用。 我也有 OpenLiberty 21.0.0.4,同样的问题也发生在那里。
我有如下所示的 ConnectionFactory 代码
public class ConnectionFactory {
private static DataSource ds = null;
...
public static Connection getDb2Connection() {
Connection conn = null;
try {
Context initCtx = new InitialContext();
ds = (DataSource) initCtx.lookup("jdbc/db2DataSource"); //NamingException is thrown here
conn = ds.getConnection();
} catch (NamingException ex) {
System.out.println(ex);
}
return conn;
}
}
我得到的例外是
javax.naming.NamingException: CWWKN0008E: An object could not be obtained for name jdbc/db2DataSource
我在下面提供了我的解决方案,即不使用 Liberty 变量 server.config.dir,而是硬编码路径,如下面的回答中所述。这不是完美的解决方案,我希望有人能够解释为什么使用 ${server.config.dir} 解析 Liberty 变量不起作用。
【问题讨论】:
-
您能分享一下您的服务器配置(server.xml 等)的关键部分吗?
标签: java-11 websphere-liberty open-liberty eclipse-2021-09