我們在同級目錄下增加
然后增加一個配置類
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