在Spring Boot Fat Jar中使用外部第三方属性文件 [英] Using external third-party properties file with Spring Boot Fat Jar

查看:245
本文介绍了在Spring Boot Fat Jar中使用外部第三方属性文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Spring Boot应用程序,它将被部署为胖子.它与Atlassian的Crowd集成以进行身份​​验证.这要求crowd.properties文件在类路径上可用.我希望不要将属性文件(包括密码)与jar捆绑在一起.

I have a Spring Boot app that will be deployed as a fat jar. It integrates with Atlassian's Crowd for authentication. This requires a crowd.properties file to be available on the classpath. I would prefer to not bundle the properties file (which includes a password) with the jar.

是否可以告诉Spring Boot包含另一个文件或目录以在哪里搜索属性文件?

过去使用独立/外部Tomcat进行此操作时,我将使用catalina.properties中的shared.loader属性指定一个目录,该目录中可以使用其他属性文件.

When doing this with a standalone/external Tomcat in the past, I would use the shared.loader property in catalina.properties to specify a directory where additional property files would be available.

我尝试将文件包含在jar的根位置以及/config位置,但无济于事. Atlassian也有一个页面,该页面指示使用-Dcrowd.properties=...命令行参数进行设置,但无济于事.

I've tried including the file in the root location of the jar, as well as a /config location, but to no avail. Atlassian also has a page that indicates using a -Dcrowd.properties=... command line parameter to set this, but also to no avail.

注意:在外部位置引用application.properties并不是 .

Note: This is not referencing application.properties in external locations.

推荐答案

好的,因此我能够借助此答案,特别是原始答案"部分.

Okay, so I was able to figure this out with the help of this answer, specifically the section under "Original answer".

事实证明,需要两部分的解决方案.

It turns out that a two part solution was required.

  1. spring-boot-maven-plugin需要进行一些配置设置.通过将layout设置为ZIP,它将使用PropertiesLauncher而不是JarLauncher,(我相信)它允许您使用加载程序属性.
  1. The spring-boot-maven-plugin needed to have some configuration set. By setting the layout to ZIP, it will use the PropertiesLauncher rather than the JarLauncher, which (I believe) allows you to use the loader properties.

`

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
        <layout>ZIP</layout>
    </configuration>
</plugin>

  1. 使用-Dloader.path=/folder/with/property/file/命令行参数提供属性文件的位置.注意:必须在-jar参数之后 .
  1. Using the -Dloader.path=/folder/with/property/file/ command line parameter to provide the location of the properties file. Note: this must come after the -jar parameter.

有关为什么的更多信息,请继续阅读.

For more information on the why, read on.

基于Spring文档的"启动可执行Jars ",共有三个启动器可为应用程序加载文件.默认情况下,使用JarLauncher,它限制了您可以检索资源的位置.另一方面,PropertiesLauncher会出现在BOOT-INF/lib/中,但也会出现在loader.path中,您可以提供其他文件夹.

Based on the Spring documentation for "Launching Executable Jars", there are three launchers to load the files for an application. By default the JarLauncher is used, which limits the locations you can retrieve resources. The PropertiesLauncher on the other hand will look in BOOT-INF/lib/ but also in loader.path, which you can provide additional folders.

这篇关于在Spring Boot Fat Jar中使用外部第三方属性文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆