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"; }
原文:https://www.cnblogs.com/luohaonan/p/12024597.html