Search code examples
mysqlspring-bootapplication.properties

Call Spring Boot Application Property From Other Property Or Java VM Option


I have a property like below in Spring Boot application.properties:

spring.datasource.url=jdbc:mysql://localhost:3306/my_db?serverTimezone=UTC&connectTimeout=10000&socketTimeout=30000

In here, I want to give "connectTimeout=10000&socketTimeout=30000" arguments with other properties like:

db.myprops=connectTimeout=10000&socketTimeout=30000
spring.datasource.url=jdbc:mysql://localhost:3306/my_db?serverTimezone=UTC&{db.myprops}

How can I handle it or Is there a specific properties in Spring Boot for connectTimeout and socketTimeout?


Solution

  • Solution by OP.

    To call it as other property in Spring-Boot Configuration:

    spring.application.property.1=property1
    spring.application.property.2=property2${spring.application.property.1}
    

    Then we can call it from Java environment to customize it like below:

    java -Dspring.application.property.1=custom -jar ../*.jar