【问题标题】:Springboot and Liberty Server - Spring JPA - Having database credentials in server settings file instead of Spring application.propertiesSpringboot 和 Liberty Server - Spring JPA - 在服务器设置文件而不是 Spring application.properties 中具有数据库凭据
【发布时间】:2021-06-22 16:25:27
【问题描述】:

我正在使用带有 Spring JPA 的 Springboot。我的应用程序正在连接到数据库,我目前正在使用

spring.datasource.url=jdbc:oracle:thin:@.....
spring.datasource.username=blahblah
spring.datasource.password=xyz

,在 Spring application.properties 文件中指定。

一切正常;但是,我们不想将这些信息提供给开发人员,而是让我们的服务器团队在运行 WAS Liberty(或 Open Liberty)的生产服务器中设置这些信息。

如何在 Liberty server.xml 中使用这些凭据并让 Spring JPA 仍然执行它需要执行的操作?

【问题讨论】:

    标签: spring-boot database-connection open-liberty


    【解决方案1】:

    Spring boot 文档here 表明您可以使用spring.datasource.jndi-name 属性来代替指向已配置数据源的JNDI 名称。

    这里是如何在 Liberty 服务器配置(server.xml 文件)中配置 Oracle 数据源,

    <server>
      <featureManager>
        <feature>jdbc-4.2</feature>
        <feature>jndi-1.0</feature>
        <!-- ... other features here -->
      </featureManager>
    
      <dataSource jndiName="jdbc/oracle">
        <jdbcDriver libraryRef="OracleJDBCLib"/>
        <properties.oracle URL="jdbc:oracle:thin:@//..." user="blahblah" password="xyz"/>
      </dataSource>
    
      <library id="OracleJDBCLib">
        <fileset dir="/path/to/oracle/ojdbc8.jar"/>
      </library>
    
    </server>
    

    然后你应该可以设置,

    spring.datasource.jndi-name=jdbc/oracle
    

    这是一个 link,用于在 Liberty 中创建数据源的文档。

    【讨论】:

    • 非常感谢@njr。正是我需要的。
    猜你喜欢
    • 2020-11-30
    • 2020-06-02
    • 2014-10-11
    • 2021-07-07
    • 1970-01-01
    • 2017-03-17
    • 1970-01-01
    • 2016-06-05
    • 2015-07-01
    相关资源
    最近更新 更多