建个文件

在启动类
@Bean
public static PropertySourcesPlaceholderConfigurer properties() {
PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer();
YamlPropertiesFactoryBean yaml = new YamlPropertiesFactoryBean();
// yaml.setResources(new FileSystemResource("AlipayConfig.yml"));//File引入
yaml.setResources(new ClassPathResource("AlipayConfig.yml"));//class引入
configurer.setProperties(yaml.getObject());
return configurer;
}
加载属性

使用的 lombok.Data; 插件免去get,set
本文介绍如何在Spring Boot项目中使用@Bean注解创建PropertySourcesPlaceholderConfigurer实例,通过YAML文件进行外部配置加载,实现应用属性的灵活管理,并利用lombok.Data注解简化实体类的get和set方法。
2704

被折叠的 条评论
为什么被折叠?



