繁体   English   中英

在Spring Boot中重命名application.properties,也可用于Spring Boot测试

[英]Rename application.properties in spring boot, also for use with spring boot test

我有一个使用Spring Boot的项目。 我需要将application.properties文件重命名为其他名称(即othername.properties)。 我需要重命名的原因是因为我们还有许多其他依赖该命名约定的脚本。

如何告诉Spring Boot使用othername.properties而不是默认的application.properties? 该文档说,我可以在运行应用程序时使用java命令并传递一个参数,但是当我运行maven> install时却无济于事,因为还要运行spring集成/单元测试(依赖于application.properties文件的数据库设置)。

现在,我试图在maven-surefire插件中设置一个环境属性,如下所示:

<build>
    <pluginManagement>
        <plugins>                               
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                    <configuration>
                        <systemPropertyVariables>
                            <spring.config.name>othername.properties</spring.config.name>
                        </systemPropertyVariables>
                    </configuration>
            </plugin>

        </plugins>
    </pluginManagement>

当我将其添加到pom.xml中时,Spring Boot似乎没有选择该文件,并且也没有从application.properties中读取(因为db设置在application.properties和othername.properties中)现在,它失败了,所以我知道它没有被读取)。

otherfile.properties在我项目的资源文件夹中,应该放在其他地方吗? 另外,如果该文件位于其他地方,如何指定该文件的相对路径?

没有尝试过,但我认为应该

<systemPropertyVariables> <spring.config.name>othername</spring.config.name> </systemPropertyVariables>

没有.properties

暂无
暂无

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

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