最近在写一个多模块的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. css3 属性阴影效果--box-shadow,text-shadow

    1.text-shadow:h-shadow v-shadow blur color; h-shadow:水平阴影的位置,可以是负值,正值向右,负值向左 v-shadow:水平阴影的位置,可以是负值, ...

  2. (Java实现) N皇后问题

    n皇后问题是一个以国际象棋为背景的问题:在n×n的国际象棋棋盘上放置n个皇后,使得任何一个皇后都无法直接吃掉其他的皇后,即任意两个皇后都不能处于同一条横行.纵行或斜线上. 蛮力法思想: 解决n皇后问题 ...

  3. Java实现有向图强连通分量的Tarjan算法

    1 问题描述 引用自百度百科: 如果两个顶点可以相互通达,则称两个顶点强连通(strongly connected).如果有向图G的每两个顶点都强连通,称G是一个强连通图.有向图的极大强连通子图,称为 ...

  4. Java实现打印回型嵌套

    *********** * * * ******* * * * * * * * *** * * * * * * * * * * *** * * * * * * * ******* * * * **** ...

  5. Python学习之斐波那契数列实现篇

    描述 一个斐波那契序列,F(0) = 0, F(1) = 1, F(n) = F(n-1) + F(n-2) (n>=2),根据n的值,计算斐波那契数F(n),其中0≤n≤1000. 输入 输入 ...

  6. 从源码研究如何不重启Springboot项目实现redis配置动态切换

    上一篇Websocket的续篇暂时还没有动手写,这篇算是插播吧.今天讲讲不重启项目动态切换redis服务. 背景 多个项目或微服务场景下,各个项目都需要配置redis数据源.但是,每当运维搞事时(修改 ...

  7. App自动化测试框架学习探索--从零开始设计

    App自动化测试框架学习探索--从零开始设计---持续更新中,敬请关注 1 批量执行app自动化测试使用多线程设计思路: 1)并发级别选择用methods 2)采用@Test多线程,数据提供类dp单线 ...

  8. 什么!你想要封装好的ajax

    ajax作为前端开发领域一个必不可少的内容,也是灵魂所在,今天就ajax的封装给大家做一个分析, 如果没有猜错的话现在基本上用原生去写ajax的意见不多了,这是肯定的 ,为什么这么说,jq的ajax大 ...

  9. 1.keras-构建基本简单网络实现线性回归

    构建基本简单网络实现线性回归 1.创建数据绘制散点图 import keras import numpy as np import matplotlib.pyplot as plt from kera ...

  10. 内核与驱动文件的version magic匹配问题

    https://blog.csdn.net/yubing_615/article/details/52183185 1.问题:本地编译的一整套底层代码down到设备跑都正常,但是由这套代码上传SVN服 ...