Springboot read application.properties files, usually there are 3 ways
1. @Value For example:
@Value ("${spring.profiles.active}")
Private String profileactive;------equivalent to injecting spring.profiles.active from the properties file into the variable profileactive
2. @ConfigurationProperties For example:
@Component
@ConfigurationProperties (locations = "Classpath:application.properties", prefix= "test")
public class Testproperties {
String URL;
String key;
}
When used in other classes, it is possible to inject the testproperties directly into the value associated with the access
3. Use enviroment for example:
Private enviroment env;
Env.getproperty ("Test.url");
And the env approach is less efficient
Note: @ConfigurationProperties can also be used for other. properties files, as long as locations is specified
Springboot reading application.properties files