Spring boot how to read properties file outside jar

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

    Actually, the most easiest way is to put application.properties and your.jar into the same directory, and just java -jar your.jar will automatically load this external config file.

    And if you are trying to load some context/files from resource folder via ClassPathResource, when you read the file don't use pathResource.getFile(), instead use pathResource.getInputStream(), getFile() works well within your IDE, however it doesn't work with the standalone jar.

提交回复
热议问题