zoukankan      html  css  js  c++  java
  • Java——spring boot打的jar包如何引用外部application.properties

    前言

    现在的项目越来越多的都是打包成jar运行,尤其是springboot项目,这时候配置文件如果一直放在项目中,每次进行简单的修改时总会有些不方便,

    问题解决

    启动类修改如下,需要把application.properties放在jar包同级目录下

    @SpringBootApplication
    @EnableScheduling
    public class Application {
        public static void main(String[] args) throws Exception {
            Properties prop = new Properties();
            String property = System.getProperty("user.dir");
            System.out.println(property);
            FileInputStream inputStream = new FileInputStream(new File(property) + "/application.properties");
            prop.load(inputStream);
            inputStream.close();
            SpringApplicationBuilder builder = new SpringApplicationBuilder(Application.class);
            SpringApplication app = builder.build();
            app.setDefaultProperties(prop);
            app.run(args);
        }
    }
  • 相关阅读:
    线程
    开启程序子进程的方式
    multiprocess模块
    计算机网络小知识
    解决粘包问题
    网络编程相关
    反射与元类
    多态相关
    封装相关与接口
    类的继承和组合
  • 原文地址:https://www.cnblogs.com/shuhao66666/p/15196329.html
Copyright © 2011-2022 走看看