简体   繁体   English

Spring Boot:从jar包中排除配置文件的配置属性

[英]Spring Boot: Exclude configuration properties for profiles from jar package

I have a Spring Boot application for which I keep a base application.properties , and then a couple of application-${profile}.properties files with configuration valid for several development environments. 我有一个Spring Boot应用程序,为其保留了一个基本application.properties ,然后保留了两个application-${profile}.properties文件,这些文件的配置对多个开发环境有效。

I want to keep those application-${profile}.properties files in source control, but as they contain private development environment details, I want to be able to create a jar package without them for distribution to third parties (ie only with the base application.properties ). 我想将那些application-${profile}.properties文件保留在源代码管理中,但是由于它们包含私有开发环境的详细信息,因此我希望能够创建一个jar包而不将其分发给第三方(即仅与基础分发)。 application.properties )。 This would force users to add their own application.properties to the classpath when executing (or configure in other ways), which is what I intend. 这将迫使用户在执行(或以其他方式配置)时将自己的application.properties添加到类路径中,这正是我想要的。

I understand I could move those profile configuration files elsewhere instead of src/main/resources so that mvn package ignores them, then add such folder to the classpath in IDE configurations... but I think there probably is a more integrated, elegant way of doing this with Boot that I'm missing... 我知道我可以将这些配置文件配置文件而不是src/main/resources移到其他位置,以便mvn package忽略它们,然后将此类文件夹添加到IDE配置中的类路径中……但是我认为可能是一种更集成,更优雅的方式我想用Boot做这个...

I have not done it myself but according to the documentation, the application is reading properties from following locations 我自己还没有做过,但是根据文档,该应用程序正在从以下位置读取属性

  1. A /config subdirectory of the current directory. 当前目录的/config子目录。
  2. The current directory A classpath /config package 当前目录A classpath /config
  3. The classpath root 类路径根

Then you can do 那你可以做

java -jar myproject.jar --spring.config.name=nameofpropertiesfile

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM