spring boot中如何引入外部application.properties呢?
下文笔者讲述SpringBoot中引入application.properties中的方法分享,如下所示
SpringBoot引入application.properties的示例
实现思路: 使用SpringApplication中setDefaultProperties设置进application.properties 即可将外部application放入SpringBoot中例:
SpringBoot引入application.properties的示例
@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); } }
版权声明
本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。