Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.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
Spring boot application-test.properties是';使用<;简介>;_Spring Boot_Spring Boot Maven Plugin - Fatal编程技术网

Spring boot application-test.properties是';使用<;简介>;

Spring boot application-test.properties是';使用<;简介>;,spring-boot,spring-boot-maven-plugin,Spring Boot,Spring Boot Maven Plugin,我正试图通过配置springbootmaven插件来使用--activate profile: <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <profiles>

我正试图通过配置
springbootmaven插件来使用--activate profile:

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
        <profiles>
            <profile>test</profile>
        </profiles>
    </configuration>
    <executions>
        <execution>
            <id>start-application</id>
            <goals>
                <goal>start</goal>
            </goals>
        </execution>
        <execution>
            <id>stop-application</id>
            <goals>
                <goal>stop</goal>
            </goals>
        </execution>
    </executions>
</plugin>
我的测试是这样的:

@ContextConfiguration(
    loader = AnnotationConfigContextLoader.class,
    initializers = ConfigFileApplicationContextInitializer.class,
    classes = TestContext.class
)
public class WhenAnonymousUserRegisterAccount extends AbstractTestNGSpringContextTests {

    @Value("${spring.mail.host}")
    private String mailHost;
TestContext
仅使用另一个属性文件定义
propertysourcesplaceplaceconfigurer

有趣的是,如果我从
应用程序中删除
并激活profile.properties
我的测试工作:

spring.profiles.active: test
因此,当我使用
Spring时,它似乎不会将
应用程序test.properties
文件加载到环境中

问题:

  • 是虫子吗
  • (如果不是)如何配置Spring以加载
    应用程序测试.properties
    和使用
  • 为什么这些方法不同

如果您在
spring boot maven插件的配置中指定配置文件,则只有在您使用该插件执行应用程序时,即通过运行
mvn spring boot:run
,配置文件才可用。我怀疑,您的集成测试不是这样的,因此它不起作用。

我在集成测试期间使用了
spring boot maven plugin
(很抱歉,我删除了该部分以缩短问题,现在我添加了它)。您究竟如何运行集成测试?此外,您还应该了解在测试中应该使用哪些注释(主要是SpringApplicationConfiguration而不是ContextConfiguration)。我不确定我使用注释的原因,因为当我从
application.properties
文件激活概要文件时,所有注释都起作用。是的,但是您配置测试的方式,测试正在初始化应用程序上下文和配置。通常测试由maven surefire插件或maven failsafe插件调用,因此spring boot maven插件的配置不适用于测试本身。你能发布maven构建的日志文件吗?dunni说了什么。您不能期望您的测试启用了配置文件。只有应用程序是可用的。在测试中使用
@ActiveProfiles(“test”)
怎么样?
spring.profiles.active: test