首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >websphere-liberty上的java web app和Postgres

websphere-liberty上的java web app和Postgres
EN

Stack Overflow用户
提问于 2016-07-20 16:45:17
回答 3查看 1.2K关注 0票数 0

我正在部署一个可以在websphere上运行的Tomcat webapp -liberty on docker。webapp连接到docker上的postgres数据源。在websphere中,当我尝试连接

代码语言:javascript
复制
DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/postgres");
Connection conn = ds.getConnection();

我的web.xml设置为:

代码语言:javascript
复制
<resource-ref>
        <description>postgreSQL Connection</description>
        <res-ref-name>jdbc/postgres</res-ref-name>
        <res-type>javax.sql.XADataSource</res-type>
        <res-auth>Container</res-auth>
    </resource-ref>

我得到以下错误

代码语言:javascript
复制
javax.naming.NamingException: CWNEN1001E: The object referenced by the java:comp/env/jdbc/postgres JNDI name could not be instantiated.
If the reference name maps to a JNDI name in the deployment descriptor bindings for the application
performing the JNDI lookup, make sure that the JNDI name mapping in the deployment descriptor binding is correct.
If the JNDI name mapping is correct, make sure the target resource
can be resolved with the specified name relative to the default initial context.
[Root exception is com.ibm.wsspi.injectionengine.InjectionException: CWNEN0030E: The
server was unable to obtain an object instance for the java:comp/env/jdbc/postgres reference.
The exception message was: CWNEN1004E: The server was unable to find the jdbc/postgres default binding with the javax.sql.XADataSource type for
the java:comp/env/jdbc/postgres reference.]

我认为这是docker网络的一个问题。我设置错了什么?我的websphere里有什么东西吗-自由?

server.xml是

代码语言:javascript
复制
<server description="Default server">

  <!-- Enable features -->
 <featureManager>
  <feature>webProfile-7.0</feature>
  <feature>adminCenter-1.0</feature>
  <feature>jdbc-4.0</feature>
</featureManager>  
  <quickStartSecurity userName="admin" userPassword="password"/>
<!-- Define the host name for use by the collective.
    If the host name needs to be changed, the server should be
    removed from the collective and re-joined. -->
<!--  <variable name="defaultHostName" value="localhost" /> -->

<!-- Define an Administrator and non-Administrator -->
<basicRegistry id="basic">
  <user name="admin" password="admin" />
  <user name="nonadmin" password="nonadminpwd" />
</basicRegistry>

<!-- Assign 'admin' to Administrator -->
<administrator-role>
  <user>admin</user>
</administrator-role>

<!--  <keyStore id="defaultKeyStore" password="Liberty" /> -->

<httpEndpoint id="defaultHttpEndpoint"
             host="*"
             httpPort="9080"
             httpsPort="9443" />

<remoteFileAccess>
  <writeDir>${server.config.dir}</writeDir>
</remoteFileAccess> 
<library id="postgres-lib">
  <fileset dir="/arturial/project/" includes="postgresql-9.4.1208.jre6.jar"/>
</library>
<dataSource id="jdbc-Prima_WA_db" jndiName="jdbc/postgres" type="javax.sql.DataSource">
  <jdbcDriver libraryRef="postgres-lib"/>
  <connectionManager numConnectionsPerThreadLocal="10" id="connectionManager" minPoolSize="1"/>
 <!--   <properties.oracle user="postgres" password="postgres" -
               url="jdbc:postgres://172.17.0.3:5432/Prima_WA_db"/> -->
 </dataSource>
<!--
<applicationManager updateTrigger="disabled"/>
<application id="primawebapp" name="primawebapp" location="war/primawebapp" type="war">
  <classLoader delegation="parentLast" commonLibraryRef="postgres-lib"/>
 </application>
-->
</server>
EN

回答 3

Stack Overflow用户

发布于 2016-07-20 17:01:07

试试这个;

代码语言:javascript
复制
DataSource ds = (DataSource)ctx.lookup("jdbc/postgres");

还有,a different way

票数 1
EN

Stack Overflow用户

发布于 2016-07-20 21:57:53

您的<datasource>必须在其下配置属性,否则Liberty将无法知道如何连接到数据库。

对于postgresql,请尝试以下配置:

代码语言:javascript
复制
<dataSource id="jdbc-Prima_WA_db" jndiName="jdbc/postgres">
  <jdbcDriver libraryRef="postgres-lib"/>
  <properties serverName="172.17.0.3" portNumber="5432" databaseName="Prima_WA_db"  
              user="postgres" password="postgres"/>
</dataSource>

当然,使用与您正在运行的postgresql实例相对应的适当值。

票数 1
EN

Stack Overflow用户

发布于 2016-07-22 16:09:13

看起来您的数据源定义可能不完整,请尝试使用以下内容更新它:

代码语言:javascript
复制
<dataSource type="javax.sql.XADataSource" ...
    <jdbcDriver javax.sql.XADataSource="org.postgresql.xa.PGXADataSource" ...
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38476467

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档