最近的练手项目使用的是 Maven 在管理项目,在使用 Maven 管理项目时,三层的开发时分模块开发的,parent-dao-service-web,所有的spring+struts + Hibernate的依赖都是加在 parent 上,dao-service-web都是作为子模块,在模块之间的关系处理的时候出现了几个问题:

  1. junit测试包的传递依赖失效了
  2. 多个配置文件的读取问题

我在 parent 工程没有添加 Junit 的依赖,在编写 dao 模块是添加了 Junit 的 jar 包,理所当然的在 scope 中写了 test 范围,但是在 service 模块中进行  Junit 测试时,显示没有依赖上 Junit 包,那是为什么呢?百度了才想通,原来是 service 依赖的 dao 模块的 install 之后的 jar 包,当 dao 模块 install 时,scope 为 test 的 Junit包当然没有被发布出来,service中也就不能传递依赖到 Junit了,这样的解决办法只能在 service 中添加 Junit 包的依赖。

因为采取的是模块式的开发,spring的配置文件就被分布在各个模块中了,在测试项目时需要读取多个模块中的 spring 配置文件时,使用到了之前没有使用到的一个注解:

@ContextConfiguration(locations={"classpath*:applicationContext-*.xml"}) 这个注解中的*号通配符表示会加载本模块和依赖的jar包中的类路径下的applicationContext-开头的配置文件(只有spring配置文件才会这样命名)

//@ContextConfiguration(locations={"classpath*:applicationContext-*.xml"})
@ContextConfiguration(locations={"classpath:applicationContext-dao.xml","classpath:applicationContext-service.xml"})
@RunWith(SpringJUnit4ClassRunner.class)
public class CustomerServiceImplTest { @Autowired
private CustomerService customerService; @Test
public void test() {
Customer customer = customerService.findById(1L);
System.out.println("********************"+customer.getCustName());
} }

最新文章

  1. Linux 进程间通讯详解一
  2. 场景7 Data Guard
  3. Hello Mybatis 02 mybatis generator
  4. Object C学习笔记19-枚举
  5. 出现“不能执行已释放的Script代码”错误的原因及解决办法
  6. SharePoint安全 - 在Goolge和Bing中查找SharePoint相关内容
  7. Send an email with format which is stored in a word document
  8. Java基础知识强化之IO流笔记49:IO流练习之 复制指定目录下指定后缀名的文件并修改名称的案例
  9. HTTP协议结构
  10. ThreadPoolExecutor的应用和实现分析(中)—— 任务处理相关源码分析 线程利用(转)
  11. 3、ABPZero系列教程之拼多多卖家工具 项目修改及优化
  12. html头部规范书写
  13. 添加python虚拟环境
  14. How to DUMP the vba code protected by Unviewable+ VBA?
  15. centos7开启80和8080端口
  16. Python中的高级数据结构详解
  17. C# winform(计算器)
  18. 231A
  19. Java基础知识学习笔记(一)
  20. SpringBoot(十一)_springboot热部署

热门文章

  1. SDR软件无线电知识要点(三)EVM
  2. 20155230 《Java程序设计》实验一(Java开发环境的熟悉) 实验报告
  3. 20155233刘高乐 第二周课堂实践以及MyOD
  4. 20155301 《Java程序设计》实验二实验报告
  5. 20155315 2016-2017-2 《Java程序设计》第三周学习总结
  6. day 11 大文件操作
  7. 【BZOJ3197】[SDOI2013]刺客信条
  8. qbxt的题:运
  9. xpath基础
  10. HBase 第四章 HBase原理