我在Spring应用程序中使用Groovy,并在测试中尝试使用多个XML配置。我试过使用@ContextHierarchy,但下面的用法示例无效:
@RunWith(SpringRunner)
@SpringBootTest
@ContextHierarchy({@ContextConfiguration("a.xml"), ContextConfiguration("b.xml")})
public class MyTest {
...
}我也尝试过:
@ContextConfiguration(locations={"a.xml", "b.xml"})但效果不太好。
据我所知,Groovy不喜欢"{“},因为它有不同的含义.?
如果定义了两个配置xml,如何在groovy中编写Testclass?
发布于 2018-01-14 12:58:29
可以使用@ContextConfiguration注释定义多个XML配置源。假设我有2个XML文件位于src/main/resources - beans1.xml和beans2.xml中。我可以在我的测试中使用它们:
@ContextConfiguration(locations = ['classpath:beans1.xml', 'classpath:beans2.xml'])与Java相比,Groovy的主要区别在于,Groovy将[]用于数组而不是Java的{},因为{}代表了Groovy的闭包。
https://stackoverflow.com/questions/48249171
复制相似问题