当前位置: 移动技术网 > IT编程>开发语言>Java > 如何使用Maven管理项目?Maven管理项目实例

如何使用Maven管理项目?Maven管理项目实例

2019年07月22日  | 移动技术网IT编程  | 我要评论

临汾摩托,龙与魔法师黑龙故事,襄樊男科

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

junit测试包的传递依赖失效了

多个配置文件的读取问题

我在 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());
 }

}

以上这篇如何使用maven管理项目?maven管理项目实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持移动技术网。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网