Springockito怎么办?

拉吉布·德卡(Rajib Deka)

我想在我的IT之一中使用Springockito模拟DAO bean。在我的IT中,我必须使用spring context.xml来自动装配某些服务,还必须使用mockApplication.xml来模拟DAO。因此,如何同时使用两个xml配置文件?

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(loader = SpringockitoContextLoader.class, locations = {"classpath*:/MockApplicationContext.xml"})
public class PayRollComponentFacadeIT {
    @Autowired
    IPayRollComponentFacade payRollComponentFacade;
    @ReplaceWithMock
    @Autowired
    IPayRollPersistenceManager payRollPersistenceManager;

我将模拟上下文包括在内 @ContextConfiguration(loader = SpringockitoContextLoader.class, locations = {"classpath*:/MockApplicationContext.xml"})

但是我还必须包括春季背景 @ContextConfiguration(locations = {"classpath*:/testApplicationContext.xml"})

问候拉吉卜

拉尔夫

ContextConfiguration.locations 是一个数组,因此您可以根据需要指定位置。

@ContextConfiguration(
       loader = SpringockitoContextLoader.class,
       locations = {"classpath*:/MockApplicationContext.xml",
                    "classpath*:/testApplicationContext.xml"}
)

顺便说一句:(这只是从我的记忆中得到的提示,我不知道问题是否仍然存在,或者我做错了什么)很久以前,当我使用两个位置参数时,我注意到了一些问题,因为它接缝会导致spring创建两个conexts (每个位置一个)。因此,我使用一个inculde包含两个普通配置文件的配置文件。(@请参阅https://stackoverflow.com/a/3414669/280244

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章