分模块开发创建service子模块——(八)

1.右击父工程新建maven子模块

 

2.填写模块名字

 

 

3.添加service模块代码与配置文件(出错是因为依赖dao层,4解决)

4.添加dao依赖

(1)更新索引

 

(2)添加dao依赖

结果:(如果dao项目为关闭是个文件夹)

5.junit测试:(添加junit包)

 

6.测试代码

 1 package cn.qlq.service.impl;
 2 
 3 import static org.junit.Assert.*;
 4 
 5 import org.junit.Test;
 6 import org.junit.runner.RunWith;
 7 import org.springframework.beans.factory.annotation.Autowired;
 8 import org.springframework.test.context.ContextConfiguration;
 9 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
10 
11 import cn.qlq.service.UserService;
12 
13 //第一种写法
14 @ContextConfiguration(locations={"classpath:applicationContext-service.xml","classpath:applicationContext-dao.xml"})
15 //第二种写法
16 //@ContextConfiguration("classpath*:applicationContext-*.xml")
17 @RunWith(SpringJUnit4ClassRunner.class)
18 public class UserServiceImplTest {
19 
20     @Autowired
21     private UserService userService;
22 
23     @Test
24     public void test() throws Exception {
25         System.out.println(userService.findUserById(1));
26     }
27 
28 }

 

结果:

 

 7.发布到本地仓库

 

结果:

8.查看本地仓库

9.依赖范围对依赖传递的影响

 

posted @ 2017-08-04 17:21  QiaoZhi  阅读(297)  评论(0编辑  收藏  举报