我有一个连接到 db2 和 oracle 数据库的 Web 服务,目前我通过在 application.properties 文件中硬编码其数据库凭据来连接我的数据库,这是一个非常糟糕的做法。
我创建了一个 java 类,在其中创建这些数据库的数据源 bean。 我的网络服务托管在 PCF 上。 所以我在 PCF 上添加了用户服务并将其绑定(bind)到我的应用程序。
但现在的问题是,由于我想在 pcf 上存储数据库凭据,我将如何在我的代码应用程序中设置连接(访问数据源对象)。
请向我提供分步过程,或者如果 github 上有任何可用的项目,请分享链接。
最佳答案
您可以使用Spring Cloud Connectors :
将服务绑定(bind)添加到您的服务绑定(bind) list
services:
- oracle-database-service
- db2-database-service
您需要将PCF内的Oracle和数据库注册为服务并绑定(bind)应用程序。 PCF documentation .
- 创建oracle服务
cf create-user-provided-service oracle-database-service -p '{"uri":"oracle://user:pass@dbhost:1521/db"}'
- 将新服务绑定(bind)到您现有的应用程序
cf bind-service <app name> oracle-database-service
- 对 db2 重复类似的步骤
- 重新启动 cf
cf restart
关于java - spring boot中如何访问pcf用户服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45845336/