简体   繁体   中英

Spring boot: Override property value

Into my application-pre.properties file there's coded this property:

scheduler.url-backoffice=http://${BACKOFFICE_SERVICE}:8080

In order to fill it, I'm using -Dspring-boot.run.arguments=--spring.config.additional-location=scheduler-config.properties .

scheduler-config.properties :

BACKOFFICE_SERVICE=localhost
scheduler.url-backoffice=http://localhost:8081

I need to set BACKOFFICE_SERVICE property, otherwise spring doesn't start. So, it means that scheduler.url-backoffice comes to http://localhost:8080 .

I 've added another line after that in order override its value.

My surprise is its value is not changed. I mean, scheduler.url-backoffice 's value is http://localhost:8080 instead of http://localhost:8081 .

I'm not able to change application-pre.properties content file.

Use multiple application properties files. One can ship in the jar; this contains the defaults. For me, defaults translates to either the prod values, if there is only one set of prod values, or the developer local values (which should cause failures in production).

The second file contains the environment specific property values that override the defaults.

You must change your startup values to achieve this. Here is an example: -Dspring-boot.run.arguments=--spring.config.additional-location=scheduler-config.properties,local-scheduler-config.properties

Edit: in response to "still not working".

It seems like you need much more than the "simple" approach I described above. For that, check out section 24. Externalized Configuration in the Spring Boot Reference Guide .

There are many techniques to override configuration values; all are covered in the reference guide.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM