springboot加载yml格式的自定义配置文件

加载yml格式的自定义配置文件

加上以下配置文件类

public class YamlPropertySourceFactory implements PropertySourceFactory {
   

    @Override
    public PropertySource< ? > createPropertySource(String name, EncodedResource resource) throws IOException {
   
        Properties propertiesFromYaml = 
  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
回答: SpringBoot在启动加载配置文件时,默认会加载application.yml或application.properties文件,如果没有明确指定spring.profiles.active属性。\[1\]如果你的项目是一个SpringBoot项目而不是SpringCloud项目,只会识别application.yml配置文件,不会读取bootstrap.yml/properties文件。\[2\]如果想在SpringBoot项目中使用bootstrap.yml配置,需要添加依赖spring-cloud-context。\[2\]在yml文件中,key: value的冒号后面需要有一个空格。\[3\]如果想让SpringBoot加载自定义yml配置文件,可以使用@PropertySource注解和@Value注解来指定目标属性在yml文件中的全限定名。同时,需要将目标类标记为@Component,以将其实例化到Spring容器中。\[3\] #### 引用[.reference_title] - *1* *2* [springcloud+springboot框架 动态加载配置文件 bootstrap.yml/properties文件](https://blog.csdn.net/qq_40448069/article/details/124929353)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [Springboot加载自定义yml文件配置的方法](https://blog.csdn.net/u010922732/article/details/91048606)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值