如何调试 Open Liberty 数据源问题

how to debug open liberty datasource issues

我的 Open Liberty 应用程序未连接到数据库。如何调试连接设置。

例如连接失败:


[INFO] Caused by: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.7.8.v20201217-ecdf3c32c4): org.eclipse.persistence.exceptions.DatabaseException
[INFO] Internal Exception: java.sql.SQLException: The server requested password-based authentication, but no password was provided. DSRA0010E: SQL State = 08004, Error Code = 0
[INFO] Error Code: 0

的评论太棒了,应该有自己的评论post:

如果您想验证 Liberty 服务器配置是否确实符合您的预期:

查看此博客:https://openliberty.io/blog/2019/09/13/testing-database-connections-REST-APIs.html

你需要

<feature>restConnector-2.0</feature> 

和一个管理员用户(如果您没有),例如

<quickStartSecurity userName="Bob" userPassword="bobpwd" /> 

现在您可以看到您的数据库配置:http://localhost:9080/ibm/api/config/dataSource/todoListDS.

对于 postgres 它应该是这样的:

{
   "configElementName": "dataSource",
   "uid": "jpadatasource",
   "id": "jpadatasource",
   "jndiName": "jpadatasource",
   "beginTranForResultSetScrollingAPIs": true,
   "beginTranForVendorAPIs": true,
   "connectionSharing": "MatchOriginalRequest",
   "enableConnectionCasting": false,
   "jdbcDriverRef": {
      "configElementName": "jdbcDriver",
      "uid": "dataSource[jpadatasource]/jdbcDriver[default-0]",
      "libraryRef": {
         "configElementName": "library",
         "uid": "postgresql-driver",
         "id": "postgresql-driver",
         "apiTypeVisibility": "spec,ibm-api,api,stable",
         "filesetRef": [
            {
               "configElementName": "fileset",
               "uid": "library[postgresql-driver]/fileset[default-0]",
               "caseSensitive": true,
               "dir": "/Users/d067570/SAPDevelop/gh/ciaas/api/target/liberty/wlp/usr/shared/resources/",
               "excludes": "",
               "includes": "postgresql-*.jar",
               "scanInterval": 0
            }
         ]
      }
   },
   "statementCacheSize": 10,
   "syncQueryTimeoutWithTransactionTimeout": false,
   "transactional": true,
   "properties.postgresql": {
      "databaseName": "postgres",
      "password": "******",
      "portNumber": 5432,
      "preparedStatementCacheQueries": 0,
      "serverName": "localhost",
      "user": "postgres"
   },
   "api": [
      "/ibm/api/validation/dataSource/jpadatasource"
   ]
}