gpt4 book ai didi

java - 带有 @RunWith(SpringJUnit4ClassRunner.class) 的配置文件

转载 作者:行者123 更新时间:2023-12-02 12:22:04 26 4
gpt4 key购买 nike

我的 TestSuite 有两种配置,它们提供不同的注入(inject) bean。只要我用注释设置我的个人资料,这就有效。

@ActiveProfiles(profiles={"a"})@ActiveProfiles(profiles={"b"})

但我似乎无法从属性源文件中设置它

我的注释看起来像

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {AConfig.class, BConfig.class })
@PropertySource("classpath:/application.properties")
@TestPropertySource(locations = {"classpath:/application.properties"})
public abstract class AbstractTestIT {
...
}

application.properties的内容是

spring.profiles.active="a"

结果是不满足的依赖关系

如上所述,使用 @ActiveProfiles 进行的设置如上所述有效,并且使用了正确的设置。

这几乎就像 PropertySource 和/或 TestPropertySource 不适用于 @RunWith(SpringJUnit4ClassRunner.class)

最佳答案

This works so long as I set my profile with an annotation.

这是预期的。

ActiveProfiles 不依赖于 spring.profiles.active 属性。

ActiveProfiles is a class-level annotation that is used to declare which active bean definition profiles should be used when loading an ApplicationContext for test classes.

作为 value 属性别名的 profiles 属性需要使用配置文件进行赋值才能激活测试

The bean definition profiles to activate.

它不使用 spring.profiles.active 属性。

spring.profiles.active 属性指定哪些配置文件在应用程序的整体配置中处于 Activity 状态,而不是在单元测试上下文中。

关于java - 带有 @RunWith(SpringJUnit4ClassRunner.class) 的配置文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45697546/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com