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 ...
随机推荐
- 分布式事务专题笔记(二)分布式事务解决方案之 2PC(两阶段提交)
个人博客网:https://wushaopei.github.io/ (你想要这里多有) 前面已经了解了分布式事务的基础理论,以理论为基础,针对不同的分布式场景业界常见的解决方案有2PC.TCC ...
- Spring ( 五 )Spring之数据访问与事务管理
个人博客网:https://wushaopei.github.io/ (你想要这里多有) 一.Spring之数据访问 1.Spring数据访问工程环境搭建 jdbc.properties配置 ...
- Java实现 蓝桥杯 算法提高 抽卡游戏
试题 算法提高 抽卡游戏 某个抽卡游戏卡池抽出限定卡的概率为p,该游戏有一个"井"的机制,抽满k次卡后直接送这张限定卡.试求获得这张限定卡需要的期望抽卡次数.输入为一行,用空格隔开 ...
- Java实现 LeetCode 674 最长连续递增序列(暴力)
674. 最长连续递增序列 给定一个未经排序的整数数组,找到最长且连续的的递增序列. 示例 1: 输入: [1,3,5,4,7] 输出: 3 解释: 最长连续递增序列是 [1,3,5], 长度为3. ...
- Java实现 LeetCode 155 最小栈
155. 最小栈 设计一个支持 push,pop,top 操作,并能在常数时间内检索到最小元素的栈. push(x) – 将元素 x 推入栈中. pop() – 删除栈顶的元素. top() – 获取 ...
- 彻底搞懂 etcd 系列文章(二):etcd 的多种安装姿势
0 专辑概述 etcd 是云原生架构中重要的基础组件,由 CNCF 孵化托管.etcd 在微服务和 Kubernates 集群中不仅可以作为服务注册与发现,还可以作为 key-value 存储的中间件 ...
- 温故知新-多线程-深入刨析volatile关键词
文章目录 摘要 volatile的作用 volatile如何解决线程可见? CPU Cache CPU Cache & 主内存 缓存一致性协议 volatile如何解决指令重排序? volat ...
- iOS -实现imageView中的button响应点击事件的方法
<pre name="code" class="cpp" style="font-size: 13px;">/** imagev ...
- 嵌入式Linux内核开发工程师必须掌握的三十道题
如果你能正确回答以下问题并理解相关知识点原理,那么你就可以算得上是基本合格的Linux内核开发工程师. 1. Linux中主要有哪几种内核锁?(进程同步与互斥) (1)自旋锁:非睡眠锁 (2)信号量: ...
- Android开源框架选择
Android开源项目推荐之「网络请求哪家强」 Android开源项目推荐之「图片加载到底哪家强」 Android网络框架的封装 Android Volley+OkHttp3+Gson(Jackson ...