【问题标题】:SpringBootTest not picking up @ProfileSpringBootTest 没有拿起@Profile
【发布时间】:2017-12-21 23:33:03
【问题描述】:

我有一个

@AutoConfigureMockMvc
@SpringBootTest(classes=[AppConfigTest])
@AcitveProfile("unittest")
ControllerTest

其中

@TestConfiguration
@Profile("unittest")
AppConfigTest 

并且位于/src/test 包下。 AppConfigTest 有 bean 来覆盖 AppConfig 中定义的 bean。 ControllerTest 运行得很好,在 AppConfigTest 而不是 AppConfig 中选择 bean。

现在,我创建

@Configuration
@Profile(["local", "unittest"])
AppConfigLocal

位于/src/main 下,如果我将 ControllerTest 更改为

@SpringBootTest(classes = [AppConfigLocal])
@ActiveProfile("unittest")
ControllerTest

现在我的 ControllerTest 似乎不再选择控制器了(测试失败,“没有找到带有 URI 的 HTTP 请求的映射...”

但它并没有真正说明为什么控制器没有连接到 mockmvc...

【问题讨论】:

标签: spring unit-testing spring-boot spring-profiles


【解决方案1】:

您@Profile 所在的包必须与您的应用所在的包相同。

【讨论】:

    猜你喜欢
    • 2015-09-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多