Spring boot further encapsulates the original configuration of spring, making the program apes a lot easier, really thanks to the spring boot
In everyday code, the read profile properties are often encountered in the business logic of their own writing, and spring boot provides two ways (I know)
1)@Value
@Value ("${profile property name}")
For example
@Value ("${agr-farmer.url}")//The Agr-farmer.url property value is placed in the URL. Private String Url;
Configuration file
Agr-farmer.url= 127.0.0.1:8009/app
What if more than one attribute should be done?
Using Annotations @ConfigurationProperties
@Component @configurationproperties (prefix= "Agr-farmer-config") Public class Agrfarmer { /// virtuals Key-value pair privatenew hashmap<> (); // Normal value Private String key; // omit Get,set Method }
The configuration file format is YML
agr-farmer-config: virtuals: key1:value1#key:value key2:value2#key:value key:t1kmknylx #单值
How spring boot reads the configuration file