【问题标题】:Two spring banners in unit tests单元测试中的两个春季横幅
【发布时间】:2022-10-12 21:35:52
【问题描述】:

我的春季启动测试中有一个奇怪的问题。 当我运行它时,控制台上打印了 2 个弹簧横幅:

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v2.5.6)

Skipping auto-registration
Default master password will be used for encryption

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v2.5.6)

Skipping auto-registration

看起来像加载了 2 个上下文。 然后我打开“Spring”选项卡,我看到有 2 个元素:

MyApplication (autotedected)
MyApplication MVC  (autotedected)

我的测试课如下

@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, properties = {"spring.main.allow-bean-definition-overriding=true"})
@ContextConfiguration(classes = {MockMvcTestConfig.class})
@AutoConfigureMockMvc
@ActiveProfiles("mvcTest")
class AuthControllerTest {
}

这怎么可能?问题可能出在哪里?

【问题讨论】:

    标签: java spring spring-boot


    【解决方案1】:

    尝试删除 @AutoConfigureMockMvc 并尝试运行

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-31
      • 1970-01-01
      • 2017-12-13
      • 2012-10-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多