Sherlie
Sherlie

Reputation: 81

How to pass database name explicitly in application.properties file not through the datasource.URL

How to pass database name explicitly in application.properties file not through the datasource.URL

spring.datasource.url = jdbc:mysql://localhost:3306/mydatabase
spring.datasource.username = root
spring.datasource.password = root

Upvotes: 0

Views: 1367

Answers (1)

Dirk Deyne
Dirk Deyne

Reputation: 6936

You could use an extra property and use it in the datasource-url like ${your-propname}

result:

database-name=mydatabase

spring.datasource.url = jdbc:mysql://localhost:3306/${database-name}
spring.datasource.username = root
spring.datasource.password = root

If you want to pass the database-name via a system-property you could use

database-name=${database:mydatabase}
spring.datasource.url = jdbc:mysql://localhost:3306/${database-name}

Here you can pass the property via java -Ddatabase=xxx... if this property is missing on startup then the default is used after the : (in example => mydatabase)

note: you should have a look at config-files-profile-specific

Upvotes: 1

Related Questions