首页 > 编程语言 > 详细

springboot#配置文件处理

时间:2019-12-11 19:30:27      阅读:82      评论:0      收藏:0      [点我收藏+]

1. 加载自定义属性文件

2. 通过bean聚合相关属性

 

1. 在启动类上通过如下注解可以加载自定义的属性文件

@PropertySource(value = {"classpath:proName.properties"},encoding = "utf-8")

@PropertySource(value = {"classpath:/config/system.properties"},encoding = "utf-8")

使用的时候直接通过@Value("${xxx.xxx.xxx:默认值}")进行使用

 

2. 如果把配置信息放置在多个配置文件中是为了解耦配置文件,那么把同类的配置信息放到一个自定义bean,就是配置信息的聚合

# system.properties
system.name=xxx
system.upload-path=/opt/app/upload

@Component
@ConfigurationProperties(prefix="system")
@PropertySource("classpath:system.properties")
@Getter
@Setter
@ToString
public class SystemConfig{
    private name = "default app name";
    private uploadPath = "/tmp/default";
}

springboot#配置文件处理

原文:https://www.cnblogs.com/luohaonan/p/12024597.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!