I am using Springboot with Spring JPA. My application is connecting to database and I am currently using
spring.datasource.url=jdbc:oracle:thin:@.....
spring.datasource.username=blahblah
spring.datasource.password=xyz
, specified in Spring application.properties file.
This is all working fine; however, we dont want to proivide this information to developers but instead let our servers team set these inside the production servers running WAS Liberty (or Open Liberty).
How to use these credentials in Liberty server.xml and have Spring JPA still do what it needs to do?
Spring boot documentation here indicates that you can use the spring.datasource.jndi-name
property instead to point at the JNDI name of a configured data source.
Here is how to configure an Oracle data source in Liberty server configuration (server.xml file),
<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>
and then you should be able to set,
spring.datasource.jndi-name=jdbc/oracle
Here is a link to documentation on creating data sources in Liberty.