【发布时间】: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