I am setting the hikari.data-source-properties
with a placeholder, but the placeholder value does not get substituted. It is a spring-boot 2.1.4.RELEASE based application. My intention is to set the Session properties so the DBAs can identify my application. Currently I get a default JDBC Thin Client
for my connection when I run SELECT PROGRAM FROM V$SESSION
from the DB
Below is what I have in my application.yml
file
spring:
datasource:
url: "jdbc:oracle:thin:@machine:1521:service_name"
driver-class-name: "oracle.jdbc.driver.OracleDriver"
hikari.data-source-properties:
v$session.program:${spring.application.name}
Below is what I have in my bootstrap.yml
file
spring:
application:
name: ms-db-service
When I query the Oracle DB, I notice that the value for program is literally ${spring.application.name}
, instead of the expected value ms-db-service
I have tried the below, with same logical result:
spring.application.name
again in the application.yml
${name}
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
return new PropertySourcesPlaceholderConfigurer();
}
spring.datasource.hikari.data-source-properties: v$session.program=${spring.application.name}
I tried the below items to gain more knowledge of the situation:
spring.datasource.url
and that worked fine@Value("${spring.datasource.hikari.data-source-properties}") String propVal;
My conclusion is that HikariCp reads these values before the placeholder substitution is done. I don't understand the relative timing of when the substitution and datasource bean creation happen in the spring-boot bean life-cycle
I am trying to avoid using a bean
for hikaricp datasource (not sure if that will even solve the issue), as I don't want to manually build the whole datasource as hikari supports huge number of properties.
So, how can I set the spring.datasource.hikari.data-source-properties
in application.yml using a placeholder. And, is there any other way to assign spring.application.name
to identify my current db connection?
You have to use it like this:
spring:
datasource:
hikari:
data-source-properties:
"[v$session.program]": ${spring.application.name}