在spring boot中重命名application.properties,也用于spring boot test

时间:2016-10-05 16:07:30

标签: java spring maven spring-boot

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

如何告诉Spring Boot使用othername.properties而不是默认的application.properties?文档说我可以使用java命令并在运行应用程序时传递参数,但是当我运行maven时,这并没有帮助>安装,因为还要运行spring integration / unit tests(它依赖于application.properties文件db设置)。

现在我尝试在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位于我项目的资源文件夹中,是否应该转到其他地方?另外,如果要在其他地方生活,我如何指定该文件的相对路径?

1 个答案:

答案 0 :(得分:1)

没试过,但我认为应该是

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

没有.properties

相关问题