IDEA创建SpringBoot的多模块项目教程
最近在写一个多模块的SpringBoot项目,基于过程总了一些总结,故把SpringBoot多个模块的项目创建记录下来。
首先,先建立一个父工程:
(1)在IDEA工具栏选择File->New->Project
(2)选择Spring Initializr,默认选择Default,然后点击Next:

(3)在输入框填写以下截图内容,点击Next

(4)直接点Next,无需选择

(5)直接点击Finish完成创建

(6)按照以上步骤,可以生成以下的项目目录结构:

(7)这时把没用的.mvn目录,src目录,mvnw还有mvnw.cmd都删除,最终只保留.gitignore和pom.xml,若是web项目,可在该pom.xml里添加以下依赖:
<!--web特征-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.3.1.RELEASE</version>
</dependency>
最终得到以下的父结构目录:

以上是创建父模块,下面创建子模块:
(1)在父模块的根目录fte上点右键,在弹出的框里选择New->Module

(2)选择Maven,点击Next

(3)填写以下内容,点击Next

(4)填写Module,点击Finish

(5)同理添加fte-controller,fte-dao,fte-service,fte-web,最终得到以下的目录结构:

(6)增加模块之间的依赖:
controller层添加以下依赖:
<dependencies>
<dependency>
<groupId>com.example</groupId>
<artifactId>fte-common</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency> <dependency>
<groupId>com.example</groupId>
<artifactId>fte-dao</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency> <dependency>
<groupId>com.example</groupId>
<artifactId>fte-service</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
service层添加以下依赖:
<dependencies>
<dependency>
<groupId>com.example</groupId>
<artifactId>fte-dao</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
(7)测试
在fte-controller创建com.zhu.fte.web包,增加以下两个类:
fteWebApplication类:
package com.zhu.fte.web; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication
public class fteWebApplication {
public static void main(String[] args) {
SpringApplication.run(fteWebApplication.class,args);
}
}
DemoController类
package java.com.zhu.fte.web; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; @RestController
@RequestMapping("demo")
public class DemoController { @GetMapping("test")
public String test(){
return "hello world";
} }
运行发现出现错误:
出现错误:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.22.2:test (default-test) on project fte-common: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.22.2:test failed: Plugin org.apache.maven.plugins:maven-surefire-plugin:2.22.2 or one of its dependencies could not be resolved: Could not transfer artifact junit:junit:jar:4.12 from/to central (https://repo.maven.apache.org/maven2): Connect to repo.maven.apache.org:443 [repo.maven.apache.org/151.101.52.215] failed: Connection timed out: connect -> [Help 1]
把缺少的org.apache.maven.plugins手动放到父工程的pom.xml里
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>2.5</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>${file.encoding}</encoding>
<!--编译的时候方法不改变方法参数名称,用于支持使用反射获取方法参数名称-->
<compilerArgument>-parameters</compilerArgument>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.4</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true
</addDefaultImplementationEntries>
</manifest>
</archive>
</configuration>
</plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.13</version>
<configuration>
<argLine>-Xmx512M -Dfile.encoding=${file.encoding}</argLine>
</configuration>
</plugin>
</plugins>
</build>
运行fteWebApplication类里的main方法,默认端口为8080,访问http://localhost:8080/demo/test,正常出现以下情况:

按照以上步骤,就可以初步建立SpringBoot多模块的项目,下一章将基于这个基础搭建Mybatis以及其逆向工程。
IDEA创建SpringBoot的多模块项目教程的更多相关文章
- SpringBoot+Mybatis多模块项目搭建教程
一.前言 框架为SpringBoot+Mybatis,本篇主要记录了在IDEA中搭建SpringBoot多模块项目的过程. 1.开发工具及系统环境 IDE:IntelliJ IDEA 2018.2 系 ...
- Spring-Boot构建多模块项目
Spring-Boot构建多模块项目 功能模块单独项目开发,可以将一个庞大的项目分解成多个小项目,便于细分开发 Maven多模块项目不能独立存在,必须有一个介质来包含. 1.创建一个Maven 项目, ...
- SpringBoot之多模块项目
SpringBoot之多模块项目 说明:我们通过maven的父子工程来搭建springboot的多模块项目** 项目的整体结构 本项目涉及了到了五个模块 framework-web模块主要是放置前端的 ...
- SpringBoot+Maven 多模块项目的构建、运行、打包实战
前言 最近在做一个很复杂的会员综合线下线上商城大型项目,单模块项目无法满足多人开发和架构,很多模块都是重复的就想到了把模块提出来,做成公共模块,基于maven的多模块项目,也好分工开发,也便于后期微服 ...
- SpringBoot+Maven 多模块项目的构建、运行、打包
SpringBoot+Maven 多模块项目的构建.运行.打包 https://blog.csdn.net/zekeTao/article/details/79413919
- SpringBoot+Maven多模块项目(创建、依赖、打包可执行jar包部署测试)完整流程
一,创建Maven多模块项目先建立外层父工程 File →new →project 选择Spring Initializr Next下一步到以下页面 工程结构如下 ...
- 基于SpringBoot构建分模块项目
前言 步骤过于详细,多图慎入!!! 假设一个场景,要开发一个4s店维修部的办公系统,其功能有:前台接待,维修抢单,财务结算,库存管理.于是我们创建一个项目balabalabala写完交工. 一段时间后 ...
- IDEA 创建 Spring Boot 多模块项目(Multi Modules)
本准备写点代码实例放到网站,太多的模板,反而每次新建工程的时候很麻烦.于是准备把这个章节的内容提前先讲讲.正好把这个代码也管理起来.话说这个多模块功能还挺爽. 写过 C# 项目用过 Visual St ...
- IDEA创建普通java和web项目教程
1.第一个javaSE项目 01.双击idea运行IDE 02.配置JDK 03.创建项目的workspace .iml文件里面是当前项目的一些配置信息! 相当于web项目中的web.xml文件 04 ...
随机推荐
- Rocket - diplomacy - LazyModule的组织方式
https://mp.weixin.qq.com/s/vaDUekxkFkOJLmzg5jCngw 简单介绍LazyModule/LazyModuleImp的组织方式. 1. LazyModule L ...
- jchdl - GSL Wire
https://mp.weixin.qq.com/s/4w_wwwCd6iBhh0QR2wK81Q org.jchdl.model.gsl.core.datatype.net.Wire.java ...
- Redis 入门到分布式 (七)Redis复制的原理与优化
一.目录 Redis复制的原理与优化 什么是主从复制 全量复制和部分复制 复制的配置 故障处理 开发运维常见问题 二. 什么是主从复制 1.单机有什么问题? 单机如果机器故障,那么久无法及时提供服务: ...
- Java实现 LeetCode 796 旋转字符串 (水题)
796. 旋转字符串 给定两个字符串, A 和 B. A 的旋转操作就是将 A 最左边的字符移动到最右边. 例如, 若 A = 'abcde',在移动一次之后结果就是'bcdea' .如果在若干次旋转 ...
- Java实现 LeetCode 506 相对名次
506. 相对名次 给出 N 名运动员的成绩,找出他们的相对名次并授予前三名对应的奖牌.前三名运动员将会被分别授予 "金牌","银牌" 和" 铜牌&q ...
- Java实现 蓝桥杯VIP 算法训练 传球游戏
[问题描述] 上体育课的时候,小蛮的老师经常带着同学们一起做游戏.这次,老师带着同学们一起做传球游戏. 游戏规则是这样的:n个同学站成一个圆圈,其中的一个同学手里拿着一个球,当老师吹哨子时开始传球,每 ...
- java代码(5) ---guava之Multiset
guava之Multiset 一.概述 Guava提供了一个新集合类型Multiset,它可以多次添加相等的元素,且和元素顺序无关,Multiset继承于JDK的Collection接口,而不是Se ...
- 根据现有Bitmap生成相同图案指定大小的新Bitmap
通过一张现有的Bitmap,画出一张同样的但是大小使我们指定的Bitmap 需求:直接createBitmap的话不允许生成的bitmap的宽高大于原始的,因此需要特定方法来将一张Bitmap的大小进 ...
- Python3和Python2中int和long的区别?
Python3:Python3中int类型的范围是动态长度的,正整数或者负整数,用sys.getsizeof()可以看int占了几位. Python2:Python2中long类型的范围是无限大小.
- 02.vue-router的进阶使用
关键字:路由懒加载,全局导航守卫,组件导航守卫,redirect重定向,keep-alive,params,query 一.目录结构 二.index.js // 配置路由相关的信 ...