使用Spring的test
导入spring-mock-version.jar和junit相关的jar包
创建一个基类继承 org.springframework.test.AbstractTransactionalDataSourceSpringContextTests;并且重写方法getConfigLocations() 例如:
protected String[] getConfigLocations() {
??????? setAutowireMode(AUTOWIRE_BY_NAME); //设置自动注入模型
??????? setDependencyCheck(false); //如果遇到什么不稳定、不满意之类的异常,必须设置为false
??????? return new String[] {
??????? ??"classpath:context/context-persistence.xml",??? //测试数据源的配置文件
??????????????? "classpath:context/web/context-dao.xml" //dao类的bean文件
??????????? };
??? }