Spring Boot新增一個YML配置文件,並進行加載


 

我們在同級目錄下增加

 

 

 

然后增加一個配置類

SpringBootConfiguration.java

import org.springframework.beans.factory.config.YamlPropertiesFactoryBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.core.io.ClassPathResource;

/**
 * @author yvioo
 */
@Configuration
public class SpringBootConfiguration {

    @Bean
    public static PropertySourcesPlaceholderConfigurer properties() {
        PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer();
        YamlPropertiesFactoryBean yaml = new YamlPropertiesFactoryBean();
       // 加載YML格式自定義配置文件 這里的 front.yml 為你新建的放在根目錄下的 yml文件名稱
        yaml.setResources(new ClassPathResource("front.yml"));
        configurer.setProperties(yaml.getObject());
        return configurer;
    }
}

 

 

IDEA中springboot項目添加yml格式配置文件 參考:https://www.cnblogs.com/pxblog/p/12304493.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM