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

Java 如何使用jUnit和Spring加载多个上下文,java,spring,junit,Java,Spring,Junit,我有一个带有以下注释的junit测试类: @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration("classpath:custom-context.xml") 在我的测试中需要的另一个上下文中存在一个自动连接的类,因此我需要加载这个上下文。如何实现这一点 我试过: @ContextConfiguration("classpath:custom-context.xml , classpath:custom-context2.x

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

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:custom-context.xml")
在我的测试中需要的另一个上下文中存在一个自动连接的类,因此我需要加载这个上下文。如何实现这一点

我试过:

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

但现在它确实可以工作了,因为它似乎没有使用
分隔符加载多个上下文。

使用字符串数组,如:

@ContextConfiguration(locations={ "classpath:custom-context.xml" , "classpath:custom-context2.xml" })

从使用字符串数组,如:

@ContextConfiguration(locations={ "classpath:custom-context.xml" , "classpath:custom-context2.xml" })

也可以这样使用widcard:

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

也可以像这样使用widcard:

@ContextConfiguration({"classpath:custom-*.xml" })
看一看。如果你有一些相似的命名模式,你也可以使用模式路径。如果有类似的命名模式,也可以使用模式路径。