前言:

   现在大部分公司用的都是基于springboot架构整合,为了方便程序开发,逐渐人们采用springboot多模块方式构建项目,本案例介绍maven项目构建,后续会用gradle进行项目搭建,感兴趣可以关注一起交流哟,本案例采用一个问答项目方式的设计架构:项目名answers;

正文:

具体步骤:

1.创建父级工程;

2.new module创建几个模块工程;

3.配置父级项目answers的 pom.xml依赖;

4.配置各模块之间的相互依赖pom.xml;

5.展示项目结构;

6.创建user;

7.service代码;

8.控制层代码;

9.postman测试;

10.打包;

详细步骤:

1.使用idea 自带的 spring initializr新建父级工程answers 删除其他成分只留下pom.xml;

2.项目名称右键new module ;

新建子工程answers-web [用于控制器层]
新建子工程answers-service   [用于service层]
新建子工程answers-domain    [用于entity实体类层]

3.配置父级项目answers的 pom.xml依赖;

gradle如何将junit与springboot结合起来的依赖 gradle搭建springboot_spring

4.配置answers-web 的pom.xml 其他模块同理加入需要的项目依赖即可

gradle如何将junit与springboot结合起来的依赖 gradle搭建springboot_xml_02

gradle如何将junit与springboot结合起来的依赖 gradle搭建springboot_xml_03

5.此时项目结构为下图:

gradle如何将junit与springboot结合起来的依赖 gradle搭建springboot_xml_04

6.answers-domain中写user类:

gradle如何将junit与springboot结合起来的依赖 gradle搭建springboot_spring_05

7.answer-service 中写逻辑业务代码

gradle如何将junit与springboot结合起来的依赖 gradle搭建springboot_xml_06

UserService.java:

gradle如何将junit与springboot结合起来的依赖 gradle搭建springboot_xml_07

UserServiceImpl.java

gradle如何将junit与springboot结合起来的依赖 gradle搭建springboot_spring_08

8.answer-web写控制层

gradle如何将junit与springboot结合起来的依赖 gradle搭建springboot_xml_09

9.启动answer-web中的application.java跑项目用postman访问接口测试

gradle如何将junit与springboot结合起来的依赖 gradle搭建springboot_spring_10


10.编译打包mvn install -DskipTests

gradle如何将junit与springboot结合起来的依赖 gradle搭建springboot_spring_11