Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在运行测试时指示Spring Boot使用测试资源中的application.properties文件_Java_Spring_Spring Boot - Fatal编程技术网

Java 如何在运行测试时指示Spring Boot使用测试资源中的application.properties文件

Java 如何在运行测试时指示Spring Boot使用测试资源中的application.properties文件,java,spring,spring-boot,Java,Spring,Spring Boot,我有以下Spring Boot应用程序的项目结构 问题是,每当我运行测试时,Spring Boot应用程序都会使用项目根目录下config文件夹中的application.properties,而不是src>test>resources文件夹中的application.properties 因此,在运行测试时,我会将application.properties的名称置乱到config文件夹中 在运行测试时,我如何告诉Spring Boot使用测试位置中的application.propertie

我有以下Spring Boot应用程序的项目结构

问题是,每当我运行测试时,Spring Boot应用程序都会使用项目根目录下config文件夹中的application.properties,而不是src>test>resources文件夹中的application.properties

因此,在运行测试时,我会将application.properties的名称置乱到config文件夹中

在运行测试时,我如何告诉Spring Boot使用测试位置中的application.properties而不触摸config>application.properties


我不想根据运行应用程序还是运行测试来不断重命名文件。

尝试这样做,它可以解决您的问题

尝试这样做,它可以解决您的问题

使用您的测试配置在src/main/resources下创建一个application-test.properties

而不是在你的测试中使用下面的方法

@ActiveProfiles("test")

使用测试配置在src/main/resources下创建application-test.properties

而不是在你的测试中使用下面的方法

@ActiveProfiles("test")

您可以在src/main/resources文件夹下创建配置文件application-test.properties,然后使用
@TestPropertySourcelocations=classpath:application-test.properties在测试中

您可以在src/main/resources文件夹下创建配置文件application-test.properties,然后使用
@ActiveProfiles("test")

@TestPropertySourcelocations=classpath:application-test.properties在您的测试中

尝试将其扩容到应用程序测试中。properties@Frischling,那没用。它抛出一个错误“无法加载应用程序上下文”,请尝试将其扩孔到应用程序测试。properties@Frischling那没用。它抛出一个错误“无法加载应用程序上下文”仍然不起作用。它正在使用config folder中的application.properties文件,但仍然无法正常工作。它正在使用config文件夹中的application.properties文件
@ActiveProfiles("test")