0

I am building a spring boot application, can application.properties value get from another property

I have an application.properties like this

spring.datasource.url= jdbc:oracle:thin:@//localhost:1521/test
org.quartz.dataSource.qDS.URL=jdbc:oracle:thin:@//localhost:1521/ORCL

can Spring boot doing like this ?

db.connections.url=jdbc:oracle:thin:@//localhost:1521/test
spring.datasource.url= db.connections.url
org.quartz.dataSource.qDS.URL=db.connections.url

2 Answers2

3

I've solved with adding ${...} to set value from other property

this is how I solved :

app.dbconnectionstring=jdbc:oracle:thin:@//localhost:1521/ORCL

#spring default datasource
spring.datasource.url=${db.dbconnectionstring}

#quartz datasource
org.quartz.dataSource.qDS.URL=${app.dbconnectionstring}
1

Spring properties that depend on other properties can be defined like below in your Class:

@Value("#{myFile:${myProperties}/myfile.txt}")
private String myFileName;

Spring can combine properties

myDir=/path/to/mydir 

myFile=${myDir}/myfile.txt

Properties file :

myDir=/path/to/mydir
Amit kumar
  • 2,169
  • 10
  • 25
  • 36