Springboot profile value method

Save some fixed, substantially constant value in the configuration file is to develop a good habit, such as a database address and other information written to the configuration file can be found in the first time when the need to change, and in many places need when cited, only if the change also changes a very convenient and practical to say

I like to use it is through @Value ( "$ {key}" ) value
approach is, for example configuration file has the following content application.yml

btcoin:
  address:
    min_1: https://www.okcoin.com/

Add the class to be used in

 @Value("${btcoin.address.min_1}")
    private String address_min_1;

This can be used directly!
In my case, all configuration information is packaged as a class, and then use @Autowired in other classes implanting configuration classes for use.

In the configuration file may reference the value in the configuration file, using $ {key} as follows

name=springboot
server.name=this is a ${name}

There are other ways to obtain the value of the profile, I think this is the easiest way to comment, and other means of their own can Baidu

Guess you like

Origin blog.csdn.net/rui15111/article/details/80970967