- Load multiple configuration files from different directories with Spring Boot
http://roufid.com/load-multiple-configuration-files-different-directories-spring-boot/
@SpringBootApplication
public class Application {
public static void main(String[] args) {
ConfigurableApplicationContext applicationContext = new SpringApplicationBuilder(Application.class)
.properties("spring.config.name:application,conf",
"spring.config.location:classpath:/external/properties/,classpath:/com/roufid/tutorial/configuration/")
.build().run(args);
ConfigurableEnvironment environment = applicationContext.getEnvironment();
System.out.println(environment.getProperty("app.firstname"));
System.out.println(environment.getProperty("conf.lastname"));
}
}
总结:加载其他的属性文件:
可以用: spring.profiles.include, 加载其他的额外的属性文件;
也可用@PropertySource("application-demo.properties")
并且: 属性文件:必须以application-xxx.properties命名:
因为 idea可以识别出,这是个 spring-boot的属性文件, 因此可以给予提示;
网友评论