在application.yml或者properties文件中添加:
info.address=USA
info.company=Spring
info.degree=high
@Value注解读取方式
@ConfigurationProperties注解读取方式
激活 @ConfigurationProperties
我们可以通过下面几种方式将其添加到应用上下文中
首先,我们可以通过添加 @Component 注解让 Component Scan 扫描到
读取指定文件
资源目录下建立config/db-config.properties:
db.username=root
db.password=123456
@PropertySource+@Value注解读取方式\
@PropertySource+@ConfigurationProperties注解读取方式
Environment读取方式
@Autowired
private Environment env;
// 获取参数
String getProperty(String key);
通过config设置开关
@conditionalonproperty(name = "XXX",havingValue = "true")
参考文献
网友评论