IDEA创建SpringBoot的多模块项目教程

简介: 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里添加以下依赖:

1<!--web特征-->

2<dependency>

3     <groupId>org.springframework.boot</groupId>

4     <artifactId>spring-boot-starter-web</artifactId>

5     <version>2.3.1.RELEASE</version>

6</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类:

packagecom.zhu.fte.web;
importorg.springframework.boot.SpringApplication;
importorg.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplicationpublicclassfteWebApplication {
publicstaticvoidmain(String[] args) {
SpringApplication.run(fteWebApplication.class,args);
     }
 }

DemoController类

packagejava.com.zhu.fte.web;
importorg.springframework.web.bind.annotation.GetMapping;
importorg.springframework.web.bind.annotation.RequestMapping;
importorg.springframework.web.bind.annotation.RestController;
@RestController@RequestMapping("demo")
publicclassDemoController {
@GetMapping("test")
publicStringtest(){
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里

1<build>2<plugins>3<plugin>4<groupId>org.apache.maven.plugins</groupId>5<artifactId>maven-clean-plugin</artifactId>6<version>2.5</version>7</plugin>8<plugin>9<groupId>org.apache.maven.plugins</groupId>10<artifactId>maven-source-plugin</artifactId>11<version>2.2</version>12</plugin>13<plugin>14<groupId>org.apache.maven.plugins</groupId>15<artifactId>maven-compiler-plugin</artifactId>16<version>3.0</version>17<configuration>18<source>1.8</source>19<target>1.8</target>20<encoding>${file.encoding}</encoding>21<!--编译的时候方法不改变方法参数名称,用于支持使用反射获取方法参数名称-->22<compilerArgument>-parameters</compilerArgument>23</configuration>24</plugin>25<plugin>26<groupId>org.apache.maven.plugins</groupId>27<artifactId>maven-install-plugin</artifactId>28<version>2.4</version>29</plugin>30<plugin>31<groupId>org.apache.maven.plugins</groupId>32<artifactId>maven-jar-plugin</artifactId>33<version>2.4</version>34<configuration>35<archive>36<manifest>37<addDefaultImplementationEntries>true38</addDefaultImplementationEntries>39</manifest>40</archive>41</configuration>42</plugin>4344<plugin>45<groupId>org.apache.maven.plugins</groupId>46<artifactId>maven-surefire-plugin</artifactId>47<version>2.13</version>48<configuration>49<argLine>-Xmx512M-Dfile.encoding=${file.encoding}</argLine>50</configuration>51</plugin>52</plugins>53</build>

运行fteWebApplication类里的main方法,默认端口为8080,访问http://localhost:8080/demo/test,正常出现以下情况:

 

按照以上步骤,就可以初步建立SpringBoot多模块的项目,下一章将基于这个基础搭建Mybatis以及其逆向工程。

目录
相关文章
|
8月前
|
JSON 分布式计算 大数据
springboot项目集成大数据第三方dolphinscheduler调度器
springboot项目集成大数据第三方dolphinscheduler调度器
510 3
|
8月前
|
Java 关系型数据库 数据库连接
Spring Boot项目集成MyBatis Plus操作PostgreSQL全解析
集成 Spring Boot、PostgreSQL 和 MyBatis Plus 的步骤与 MyBatis 类似,只不过在 MyBatis Plus 中提供了更多的便利功能,如自动生成 SQL、分页查询、Wrapper 查询等。
804 3
|
8月前
|
Java 测试技术 Spring
简单学Spring Boot | 博客项目的测试
本内容介绍了基于Spring Boot的博客项目测试实践,重点在于通过测试驱动开发(TDD)优化服务层代码,提升代码质量和功能可靠性。案例详细展示了如何为PostService类编写测试用例、运行测试并根据反馈优化功能代码,包括两次优化过程。通过TDD流程,确保每项功能经过严格验证,增强代码可维护性与系统稳定性。
327 0
|
8月前
|
存储 Java 数据库连接
简单学Spring Boot | 博客项目的三层架构重构
本案例通过采用三层架构(数据访问层、业务逻辑层、表现层)重构项目,解决了集中式开发导致的代码臃肿问题。各层职责清晰,结合依赖注入实现解耦,提升了系统的可维护性、可测试性和可扩展性,为后续接入真实数据库奠定基础。
648 0
|
分布式计算 大数据 Java
springboot项目集成大数据第三方dolphinscheduler调度器 执行/停止任务
springboot项目集成大数据第三方dolphinscheduler调度器 执行/停止任务
205 0
|
Java Windows
IntelliJ IDEA 2020.2激活破解教程
IntelliJ IDEA 2020.2激活破解教程
2876 1
IntelliJ IDEA 2020.2激活破解教程
|
IDE Linux 开发工具
IntelliJ IDEA2022破解IDEA2022.2永久破解激活教程
IDEA 目前已经更新到最新的 2022.2.2 版本了,群里的小伙伴私聊问我,为啥之前 2021.3.1 的激活套路对新版本 2022.2.2 不管用了,是个什么情况? 很显然,IDEA 官方发现了这种破解路数,新版本加入了更严厉的反制破解。所以说,小伙伴们破解成功了以后,尽量不要升级 IDEA, 不然大概率又不行了。 好在z大又更新了新的补丁,针对最新版本,这边笔者亲测可行,仅以下文记录本人 IntelliJ IDEA 2022.2.2 版本的激活破解到 2099 年的全过程,步骤非常详细,跟着图文来就行~
68336 3
IntelliJ IDEA2022破解IDEA2022.2永久破解激活教程
IntelliJ IDEA 2022.2 9月最新激活破解教程(永久激活,亲测有效)
IntelliJ IDEA 2022.2 9月最新激活破解教程(永久激活,亲测有效)
5953 0
IntelliJ IDEA 2022.2 9月最新激活破解教程(永久激活,亲测有效)
|
安全 IDE Linux
IDEA激活码2022.1最新激活注册码–破解教程「永久激活,亲测有效果」
1、安装IDEA,一路next即可,遇到安装路径时,记得修改安装路径。 2、安装完成,打开IDEA,会先弹出一个注册框,勾选Evaluate for free,点击Evaluate,然后进入主界面 3. 开始破解
32464 0
IDEA激活码2022.1最新激活注册码–破解教程「永久激活,亲测有效果」

热门文章

最新文章