gpt4 book ai didi

java - 如何使用 jUnit 和 Spring 加载多个上下文

转载 作者:行者123 更新时间:2023-11-29 07:52:31 25 4
gpt4 key购买 nike

我有一个带有以下注释的 junit 测试类:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:custom-context.xml")

在我的测试中需要 Autowiring 的另一个上下文中存在一个类,因此我需要加载该上下文。如何实现?

我试过了:

@ContextConfiguration("classpath:custom-context.xml , classpath:custom-context2.xml")

但这现在确实有效,因为它似乎没有使用 , 分隔符加载多个上下文。

最佳答案

也可以像这样使用widcard:

@ContextConfiguration({"classpath:custom-*.xml" })

关于java - 如何使用 jUnit 和 Spring 加载多个上下文,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20053191/

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