0

I want to reuse a Spring property in application.properties.

For example I have the following application.properties:

spring.data.mongodb.database=my_database
org.jobrunr.database.databaseName=my_database

How can I reuse the value (my_database) of the property (spring.data.mongodb.database) for the other property (org.jobrunr.database.databaseName) , so I only have to specify the database name at one place.

LeTest
  • 73
  • 7
  • 4
    Define which one you want to use and replace the other with `${spring.data.mongodb.database}` (or vice-versa). Or specify a dedicated property (`my.databaseName`) and replace both with `${my.databaseName}`. – M. Deinum Sep 19 '22 at 09:24

1 Answers1

2

Answer

Such as M.Deinum said :

my.database.name=my_database

spring.data.mongodb.database=${my.database.name}
org.jobrunr.database.databaseName=${my.database.name}

You can now use the property ${my.database.name} wherever you need the value my_database.


Let us know how it goes! :)

riccadema
  • 116
  • 1
  • 5