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);
}
posted @ 2021-09-16 09:28  留一抹清风  阅读(163)  评论(0编辑  收藏  举报