第一套方案:
1、初始化application:使用@ContextConfigurationr的classpath属性,如
@ContextConfiguration(locations =
{ "/META-INF/spring/applicationContext-mutiDs.xml", "/META-INF/spring/applicationContext-timer.xml" })
@RunWith(SpringJUnit4ClassRunner.class)
@TestExecutionListeners({DependencyInjectionTestExecutionListener.class, DirtiesContextTestExecutionListener.class})
@TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = true)
@Transactional
public class A
或者
在@Before
public void prepareInit() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath*:META-INF/spring/*.xml");
context.start();
}
第二套方案:
1、使用自己的application.xml和自己的数据
@ContextConfiguration(locations = {"file:src/test/resources/applicationContext.xml",
"file:src/test/resources/dubbo-mdb-provider.xml"})
2、然后把相关的数据库配置放在test目录下面。
3、搞定,两套方案完成。