Spring boot how to read properties file outside jar

后端 未结 6 1766
悲&欢浪女
悲&欢浪女 2020-11-30 04:42

in my target folder, there are 2 folders, lib and conf. all the properties files are placed in conf folder, and jars are placed in lib foulder.

previous to spring

6条回答
  •  盖世英雄少女心
    2020-11-30 05:24

    I'm a bit confused by the title of the question and the description. Hopefully I won't confuse you even more with my comments.

    In general, Spring Boot is VERY opiniated about project structure as well as the binary created. The recomended way (Spring Boot opinion) is to build a jar with all dependencies inside (fat jar). If you need configuration properties defined outside your fat jar (or war if that's what you built), Spring Boot offers many options (see reference 1). I like my apps to point to an external file using the flag (spring.config.location) which can be set with a system property:

    java -jar -Dspring.config.location= myBootProject.jar
    

    Notice that you can do something similar by using an environment variable to define where your external file lives.

    I hope this helps!

    References: 1. https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html

提交回复
热议问题