核心配置文件
application.properties
application.yml application.yaml
都可以作为配置文件,同时存在时只用.properties
多环境的核心配置文件
一
application-test.prperties 必须以application- 开头。
多环境配置文件时需要进行环境切换,只需要在主核心配置文件中用
spring.profiles.active=test
来指定利用test环境下的配置文件
二
yml yaml 同上
配置文件中的配置属性
school.name=bjpowernode
school.websit=http://www.bjpowernode.com
abc.name=abc
abc.websit=http://www.abc.com
通过实体类的方式获取
@Component //交给spring容器
@ConfigurationProperties(prefix = "school")
public class School {
private String name;
private String websit;
然后可以在controller中通过
@Autowired
private School school;
的方式获取