问题描述
我想在我的一个 IT 中使用 Springockito 模拟 DAO bean.在我的 IT 中,我必须使用 spring context.xml 来自动装配一些服务,还必须使用 mockApplication.xml 来模拟 DAO.那么,如何同时使用两个xml配置文件呢?
I want to mock DAO bean using Springockito in one of my IT. In my IT I have to use spring context.xml to autowire some services and also mockApplication.xml to mock the DAOs. So, how can I use both the xml configuration files at the same time?
@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"})
I have included mock context as @ContextConfiguration(loader = SpringockitoContextLoader.class, locations = {"classpath*:/MockApplicationContext.xml"})
但我还必须包含 spring 上下文 @ContextConfiguration(locations = {"classpath*:/testApplicationContext.xml"})
But I have to include the spring context also @ContextConfiguration(locations = {"classpath*:/testApplicationContext.xml"})
问候拉吉布
推荐答案
ContextConfiguration.locations
是一个数组,因此您可以根据需要指定位置.
ContextConfiguration.locations
is an Array, so you can specifiy as may locaction you want.
@ContextConfiguration(
loader = SpringockitoContextLoader.class,
locations = {"classpath*:/MockApplicationContext.xml",
"classpath*:/testApplicationContext.xml"}
)
顺便说一句:(这只是我记忆中的一个提示,我不知道问题是否仍然存在,或者我做错了什么)很久以前,我在使用两个位置参数时注意到了一些问题,因为它接缝弹簧创建两个上下文(每个位置一个).因此,我使用一个配置文件,inculde
是两个普通配置文件.(@见https://stackoverflow.com/a/3414669/280244)
BTW: (this is only a hint from my memory, I dont know if the problem still exists, or if I have done something wrong)Long time ago I noticed some problems when using two location parameters, because it seams that spring create two conexts (one for each location). Therefor I use an single configuration file that inculde
s the two normal configuration files. (@see https://stackoverflow.com/a/3414669/280244)
这篇关于Springockito 怎么用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!