sringboot项目如何通过编程式使用指定路径下的application.properties


注意:jar包里如果有application.properties文件,会覆盖编程里指定的配置文件

@SpringBootApplication
public class IogTagApp {

public static void main(String[] args) throws Exception{
// SpringApplication.run(IogTagApp.class, args);

Properties defaultProperties = new Properties();
InputStream in;
try {
in = new FileInputStream("/app/conf/application.properties");
defaultProperties.load(in);
in.close();
} catch (IOException e) {
}
SpringApplication app = new SpringApplication(IogTagApp.class);
app.setDefaultProperties(defaultProperties);
app.run(args);
}
原文地址:https://www.cnblogs.com/zjting/p/15292130.html