简体   繁体   中英

application.properties file from child application not override application.properties file in main application

I am new to spring boot,I have a confusion that , when all the property source in spring application like application.properties , my.properties,application-{profile}.properties goes into Environment, then why don't they get override. if there are some common key in two different properties file.

eg, If I create one child project and have one application.properties in it and having propety let say 'name=child' and create the jar of this project and add this jar to my main project and main project also having an application.properties file with same key but different value, let say 'name=parent' if I use Envionment class in spring and get env.getProperty(key) then it is showing parent. Acc to me it should be 'child' because if all property are going to same place then two same key with different value cannot exist.

And also I have confusion of Ordering of properties file. Does it mean if it get property in first file then it will not got to second file to search for that propety?

Spring boot has an order for evaluating all property sources. They are listed here: https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html

So basically, Spring knows about all the properties it needs to source. It will then evaluate where to get them. In your case, it evaluates your {profile}.properties file first. If it can't find what it needs, then it will go into your regular application.properties. So if you are expecting your application.properties values to overwrite the {profile} one, it's not going to.

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