1

我将 Groovy 用于我的 Spring 应用程序,并尝试在我的测试中使用多个 XML bean 配置。我尝试使用@ContextHierarchy但以下用法示例不起作用:

@RunWith(SpringRunner)
@SpringBootTest
@ContextHierarchy({@ContextConfiguration("a.xml"), ContextConfiguration("b.xml")})
public class MyTest {

...

}

我也试过:

@ContextConfiguration(locations={"a.xml", "b.xml"})

但效果不佳。

据我了解,Groovy 不喜欢“{”“}”,因为它的含义不同......?

如何在定义了两个配置 xml 的 groovy 中编写 Testclass?

4

1 回答 1

1

@ContextConfiguration您可以使用注释定义多个 XML 配置源。假设我有 2 个 XML 配置文件位于src/main/resources-beans1.xmlbeans2.xml. 我可以在我的测试中使用它们:

@ContextConfiguration(locations = ['classpath:beans1.xml', 'classpath:beans2.xml'])

与 Java 相比的主要区别在于 Groovy 使用[]数组而不是 Java 的{},因为{}代表了 Groovy 的闭包。

于 2018-01-14T12:58:29.080 回答