代码之家  ›  专栏  ›  技术社区  ›  code4kix

可执行JAR-JVM参数-外部化配置属性-Spring Boot Maven插件

  •  0
  • code4kix  · 技术社区  · 6 年前

    我们有一个spring启动应用程序,在属性文件中有外部化的配置。执行jar文件如下:
    java -jar -Dspring.config.location="application.properties" app.jar

    像下面这样直接执行jar是可行的,但是没有属性文件。现在,下面的这些选项都不接受属性文件。
    ./app.jar
    ./app.jar -Dspring.config.location="file:./application.properties"

    我希望我们能在未来做点什么pom.xml文件或者在执行的命令中。

    仅供参考,我们在pom.xml 要为我们构建jar文件:

                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                    <configuration>
                       <executable>true</executable>
                       <includeSystemScope>true</includeSystemScope>
    <!--                   This below does not work -->
    <!--                   <jvmArguments> -->
    <!--                      -Dspring.config.location=application.properties -->
    <!--                   </jvmArguments> -->
                    </configuration>
                    <executions>
                        <execution>
                            <goals>
                                <goal>repackage</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
    
    0 回复  |  直到 6 年前
        1
  •  0
  •   qavid    6 年前

    创建文件: 应用程序配置

    JAVA_OPTS="-Dspring.config.location=application.properties"
    

    类似的问题也得到了回答 here here