Spring boot how to read properties file outside jar

后端 未结 6 1723
悲&欢浪女
悲&欢浪女 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:36

    Found another solution.

    put every configuration in one application.properties files, and in code use @Value("${name}") to read.

    and use a assembly file to copy the resource folders' file into target config folder.

    and after deploy, just need to change application.properties file in config folder and the run the application.

    this because spring boot read application.properties file in follow sequence.

    • The /config subdirectory located in the current directory

    • The current directory

    • A classpath /config package

    • The classpath root

    but this works for one properties file. not for multiply properties files

提交回复
热议问题