最近在写一个多模块的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的多模块项目教程的更多相关文章

  1. SpringBoot+Mybatis多模块项目搭建教程

    一.前言 框架为SpringBoot+Mybatis,本篇主要记录了在IDEA中搭建SpringBoot多模块项目的过程. 1.开发工具及系统环境 IDE:IntelliJ IDEA 2018.2 系 ...

  2. Spring-Boot构建多模块项目

    Spring-Boot构建多模块项目 功能模块单独项目开发,可以将一个庞大的项目分解成多个小项目,便于细分开发 Maven多模块项目不能独立存在,必须有一个介质来包含. 1.创建一个Maven 项目, ...

  3. SpringBoot之多模块项目

    SpringBoot之多模块项目 说明:我们通过maven的父子工程来搭建springboot的多模块项目** 项目的整体结构 本项目涉及了到了五个模块 framework-web模块主要是放置前端的 ...

  4. SpringBoot+Maven 多模块项目的构建、运行、打包实战

    前言 最近在做一个很复杂的会员综合线下线上商城大型项目,单模块项目无法满足多人开发和架构,很多模块都是重复的就想到了把模块提出来,做成公共模块,基于maven的多模块项目,也好分工开发,也便于后期微服 ...

  5. SpringBoot+Maven 多模块项目的构建、运行、打包

    SpringBoot+Maven 多模块项目的构建.运行.打包 https://blog.csdn.net/zekeTao/article/details/79413919

  6. SpringBoot+Maven多模块项目(创建、依赖、打包可执行jar包部署测试)完整流程

    一,创建Maven多模块项目先建立外层父工程         File →new →project  选择Spring Initializr          Next下一步到以下页面 工程结构如下 ...

  7. 基于SpringBoot构建分模块项目

    前言 步骤过于详细,多图慎入!!! 假设一个场景,要开发一个4s店维修部的办公系统,其功能有:前台接待,维修抢单,财务结算,库存管理.于是我们创建一个项目balabalabala写完交工. 一段时间后 ...

  8. IDEA 创建 Spring Boot 多模块项目(Multi Modules)

    本准备写点代码实例放到网站,太多的模板,反而每次新建工程的时候很麻烦.于是准备把这个章节的内容提前先讲讲.正好把这个代码也管理起来.话说这个多模块功能还挺爽. 写过 C# 项目用过 Visual St ...

  9. IDEA创建普通java和web项目教程

    1.第一个javaSE项目 01.双击idea运行IDE 02.配置JDK 03.创建项目的workspace .iml文件里面是当前项目的一些配置信息! 相当于web项目中的web.xml文件 04 ...

随机推荐

  1. STL中的迭代器分类

      STL中迭代器的分类 五类迭代器如下: 1.输入迭代器:只读,一次传递    为输入迭代器预定义实现只有istream_iterator和istreambuf_iterator,用于从一个输入流i ...

  2. Rocket - tilelink - ProbePicker

      简单介绍ProbePicker的实现.   ​​   1. 基本介绍   用于把多个Cache client合并成一个: ​​   2. diplomacy node   ProbePicker的 ...

  3. Rocket - tilelink - Monitor

    https://mp.weixin.qq.com/s/6e-G5RSQc7Xje7mQj8-Lag   简单介绍Monitor的实现.   ​​   1. 基本介绍   用于监控各个channel上的 ...

  4. Java实现 LeetCode 427 建立四叉树

    427. 建立四叉树 我们想要使用一棵四叉树来储存一个 N x N 的布尔值网络.网络中每一格的值只会是真或假.树的根结点代表整个网络.对于每个结点, 它将被分等成四个孩子结点直到这个区域内的值都是相 ...

  5. Java实现 蓝桥杯VIP 算法训练 黑白无常

    算法训练 黑白无常 时间限制:1.0s 内存限制:256.0MB 问题描述 某寝室的同学们在学术完之后准备玩一个游戏:游戏是这样的,每个人头上都被贴了一张白色或者黑色的纸,现在每个人都会说一句话&qu ...

  6. Java实现 LeetCode 58 最后一个单词的长度

    58. 最后一个单词的长度 给定一个仅包含大小写字母和空格 ' ' 的字符串 s,返回其最后一个单词的长度. 如果字符串从左向右滚动显示,那么最后一个单词就是最后出现的单词. 如果不存在最后一个单词, ...

  7. java实现 洛谷 P1014 Cantor表

    题目描述 现代数学的著名证明之一是Georg Cantor证明了有理数是可枚举的.他是用下面这一张表来证明这一命题的: 1/1 1/2 1/3 1/4 1/5 - 2/1 2/2 2/3 2/4 - ...

  8. Java实现One-way traffic(单向交通)

    One-way traffic In a certain town there are n intersections connected by two- and one-way streets. T ...

  9. Java实现 蓝桥杯 历届试题 城市建设

    问题描述 栋栋居住在一个繁华的C市中,然而,这个城市的道路大都年久失修.市长准备重新修一些路以方便市民,于是找到了栋栋,希望栋栋能帮助他. C市中有n个比较重要的地点,市长希望这些地点重点被考虑.现在 ...

  10. CSS 简介/特点/优势/给特定浏览器提供不同样

    1.CSS简介 CSS全称Cascading Style Sheet,可译为“层叠样式表”或“级联样式表”,通常称为CSS样式或者样式表.CSS是一些纯文本内容,文件格式为.css. 2.CSS特点 ...