Use annotations to read the data in the configuration file and mapped to the entity class or property
Mapped to the property above
Step a: Add the following comments on the Controller layer
@PropertySource("classpath:application.properties")//加载配置文件
Step two: Add the following comments on the Controller layer
@Value("${Web.file.path}") //通过注解,读取配置文件中的数据,并映射到类的属性上面
Step three: add the following code in application.properties
Web.file.path=F:\\
Mapped to the entity class
Step 1: Add the following annotation layer Utils
@PropertySource("classpath:application.properties")//加载配置文件
//用于读取配置文件中的指定的键值对(key-value)映射到java实体类,注意前缀要小写,不能有下划线
@ConfigurationProperties(prefix = "server")
Step two: add the following code on the property
@Value the same content of the prefix and a step of
@Value("${server.name}")
private String name;
@Value("${server.ip}")
private String ip;
Step three: add the following code in application.properties
#读取配置文件键值对(key-val)映射到 实体类 serverUtils
server.name=centos7
server.ip=192.168.1.17