【SpringBoot】多模块项目结构搭建
程序员文章站
2022-09-21 15:16:16
必需学会SpringBoot基础知识 Takes an opinionated view of building production-ready Spring applications. Spring Boot favors convention over configuration and is ......
前言:
必需学会SpringBoot基础知识
简介:
Takes an opinionated view of building production-ready Spring applications. Spring Boot favors convention over configuration and is designed to get you up and running as quickly as possible.
工具:
JDK8
apache-maven-3.5.2
IntelliJ IDEA 2018.1.3 x64
准备工作
通过之前章节进行改造,更符合企业需求。
先做一个简单
理论分析
模型层: model
持久层: persostence
表示层: web
web 依赖 persostence
persostence 依赖 model
选中项目右键点击 New –> Module,选择 Maven 下一步 填写 artifactId (web) 然后,一直下一步到完成;
然后从原始项目里移植代码
如此类推的把另外一个也新建起来
好了! 下面到pom文件加入依赖, 大家应该也有看上面我写的准备工作把? 对 就按这个做!
first-app-demo
-
需要手动修改为pom
-
<modules> 是在新建子目录的时候自动增加的,并非手动
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.lwc</groupId> <artifactId>first-app-demo</artifactId> <version>0.0.1-SNAPSHOT</version> <modules> <module>web</module> <module>persostence</module> <module>model</module> </modules> <!--修改成 pom--> <packaging>pom</packaging> <!-- 模型层: model 持久层: persostence 表示层: web web 依赖 persostence persostence 依赖 model web UserController -> UserRepository -> User --> <name>first-app-demo</name> <description>Demo project for Spring Boot</description> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.2.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-webflux</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>io.projectreactor</groupId> <artifactId>reactor-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
web.pom
-
web 依赖 persostence (复制persostence的<parent>里面的<groupId>、<version>、<artifactId>到 web 的 pom 文件里面)
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> <artifactId>first-app-demo</artifactId> <groupId>com.lwc</groupId> <version>0.0.1-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>web</artifactId> <dependencies> <!-- 添加对persostence依赖 --> <dependency> <groupId>com.lwc</groupId> <artifactId>persostence</artifactId> <version>0.0.1-SNAPSHOT</version> </dependency> </dependencies> </project>
persostence.pom
-
persostence 依赖 model (原理和上面一样)
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> <artifactId>first-app-demo</artifactId> <groupId>com.lwc</groupId> <version>0.0.1-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>persostence</artifactId> <dependencies> <!-- 添加对model依赖 --> <dependency> <groupId>com.lwc</groupId> <artifactId>model</artifactId> <version>0.0.1-SNAPSHOT</version> </dependency> </dependencies> </project>
model.pom
-
不需要依赖任何东西
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> <artifactId>first-app-demo</artifactId> <groupId>com.lwc</groupId> <version>0.0.1-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>model</artifactId> </project>
最后Build一下,启动项目。 完成!
源码下载
https://github.com/eddie-code/SpringBootDemo/tree/master/first-app-demo
上一篇: 【CCF】全国信息学奥林匹克联赛模拟题+解析+代码
下一篇: 高考建议
推荐阅读
-
Java--IDEA创建多服务模块的SpringCloud微服务项目
-
MVC项目结构搭建及单个类的实现学习笔记1
-
基于【 springBoot +springCloud+vue】的项目之一 || 后端搭建
-
eclipse搭建springboot的项目
-
SpringBoot技术栈搭建个人博客【项目准备】
-
深入理解Vue-cli搭建项目后的目录结构探秘
-
基于vue-cli搭建多模块且各模块独立打包的项目
-
在eclipse中使用Maven分模块搭建SSM框架,创建jar、war、pom工程模块教学,项目的热部署,需要的可以留下邮箱,给大家发整理过的Maven笔记
-
springboot多模块多环境配置文件问题(动态配置生产和开发环境)
-
idea使用spring Initializr 快速搭建springboot项目遇到的坑