springboot基于maven多模块项目搭建(直接启动webApplication)
1. 新建maven项目springboot-module
2.把src删掉,新建module项目
springboot-module-api
springboot-module-model
springboot-module-service
springboot-module-util
springboot-module-web
3. 添加模块之间的依赖
3.1 springboot-module.pom
1 <?xml version="1.0" encoding="UTF-8"?> 2 <project xmlns="http://maven.apache.org/POM/4.0.0" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 5 <modelVersion>4.0.0</modelVersion> 6 7 <groupId>com.springboot.module</groupId> 8 <artifactId>springboot-module</artifactId> 9 <packaging>pom</packaging> 10 <version>1.0-SNAPSHOT</version> 11 <modules> 12 <module>springboot-module-api</module> 13 <module>springboot-module-model</module> 14 <module>springboot-module-service</module> 15 <module>springboot-module-util</module> 16 <module>springboot-module-web</module> 17 </modules> 18 19 <!-- Spring boot 父引用--> 20 <parent> 21 <groupId>org.springframework.boot</groupId> 22 <artifactId>spring-boot-starter-parent</artifactId> 23 <version>1.4.1.RELEASE</version> 24 </parent> 25 <dependencies> 26 <!-- Spring boot 核心web--> 27 <dependency> 28 <groupId>org.springframework.boot</groupId> 29 <artifactId>spring-boot-starter-web</artifactId> 30 </dependency> 31 <dependency> 32 <groupId>org.projectlombok</groupId> 33 <artifactId>lombok</artifactId> 34 <version>1.16.18</version> 35 </dependency> 36 <dependency> 37 <groupId>org.springframework.boot</groupId> 38 <artifactId>spring-boot-starter-logging</artifactId> 39 </dependency> 40 <dependency> 41 <groupId>org.springframework.boot</groupId> 42 <artifactId>spring-boot-starter-test</artifactId> 43 </dependency> 44 </dependencies> 45 46 <build> 47 <plugins> 48 <plugin> 49 <groupId>org.springframework.boot</groupId> 50 <artifactId>spring-boot-maven-plugin</artifactId> 51 <executions> 52 <execution> 53 <goals> 54 <goal>repackage</goal> 55 </goals> 56 </execution> 57 </executions> 58 <configuration> 59 <executable>true</executable> 60 </configuration> 61 </plugin> 62 </plugins> 63 </build> 64 </project>
3.2 springboot-module-api.pom
1 <?xml version="1.0" encoding="UTF-8"?> 2 <project xmlns="http://maven.apache.org/POM/4.0.0" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 5 <parent> 6 <artifactId>springboot-module</artifactId> 7 <groupId>com.springboot.module</groupId> 8 <version>1.0-SNAPSHOT</version> 9 </parent> 10 <modelVersion>4.0.0</modelVersion> 11 <artifactId>springboot-module-api</artifactId> 12 13 <dependencies> 14 <dependency> 15 <groupId>com.springboot.module</groupId> 16 <artifactId>springboot-module-util</artifactId> 17 <version>1.0-SNAPSHOT</version> 18 <scope>compile</scope> 19 </dependency> 20 </dependencies> 21 </project>
3.3 springboot-module-model.pom
1 <?xml version="1.0" encoding="UTF-8"?> 2 <project xmlns="http://maven.apache.org/POM/4.0.0" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 5 <parent> 6 <artifactId>springboot-module</artifactId> 7 <groupId>com.springboot.module</groupId> 8 <version>1.0-SNAPSHOT</version> 9 </parent> 10 <modelVersion>4.0.0</modelVersion> 11 <artifactId>springboot-module-model</artifactId> 12 13 <dependencies> 14 <dependency> 15 <groupId>org.springframework.boot</groupId> 16 <artifactId>spring-boot-starter-data-jpa</artifactId> 17 </dependency> 18 <dependency> 19 <groupId>mysql</groupId> 20 <artifactId>mysql-connector-java</artifactId> 21 </dependency> 22 <dependency> 23 <groupId>com.springboot.module</groupId> 24 <artifactId>springboot-module-util</artifactId> 25 <version>1.0-SNAPSHOT</version> 26 <scope>compile</scope> 27 </dependency> 28 </dependencies> 29 30 </project>
3.4 springboot-module-service.pom
1 <?xml version="1.0" encoding="UTF-8"?> 2 <project xmlns="http://maven.apache.org/POM/4.0.0" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 5 <parent> 6 <artifactId>springboot-module</artifactId> 7 <groupId>com.springboot.module</groupId> 8 <version>1.0-SNAPSHOT</version> 9 </parent> 10 <modelVersion>4.0.0</modelVersion> 11 <artifactId>springboot-module-service</artifactId> 12 13 <dependencies> 14 <dependency> 15 <groupId>com.springboot.module</groupId> 16 <artifactId>springboot-module-model</artifactId> 17 <version>1.0-SNAPSHOT</version> 18 </dependency> 19 <dependency> 20 <groupId>com.springboot.module</groupId> 21 <artifactId>springboot-module-api</artifactId> 22 <version>1.0-SNAPSHOT</version> 23 </dependency> 24 <dependency> 25 <groupId>ma.glasnost.orika</groupId> 26 <artifactId>orika-core</artifactId> 27 <version>1.5.1</version> 28 </dependency> 29 <dependency> 30 <groupId>org.apache.commons</groupId> 31 <artifactId>commons-lang3</artifactId> 32 <version>3.5</version> 33 </dependency> 34 </dependencies> 35 </project>
3.5 springboot-module-util.pom
1 <?xml version="1.0" encoding="UTF-8"?> 2 <project xmlns="http://maven.apache.org/POM/4.0.0" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 5 <parent> 6 <artifactId>springboot-module</artifactId> 7 <groupId>com.springboot.module</groupId> 8 <version>1.0-SNAPSHOT</version> 9 </parent> 10 <modelVersion>4.0.0</modelVersion> 11 <artifactId>springboot-module-util</artifactId> 12 13 <dependencies> 14 <dependency> 15 <groupId>org.springframework.boot</groupId> 16 <artifactId>spring-boot-starter-data-jpa</artifactId> 17 </dependency> 18 </dependencies> 19 </project>
3.6 springboot-module-web.pom
1 <?xml version="1.0" encoding="UTF-8"?> 2 <project xmlns="http://maven.apache.org/POM/4.0.0" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 5 <parent> 6 <artifactId>springboot-module</artifactId> 7 <groupId>com.springboot.module</groupId> 8 <version>1.0-SNAPSHOT</version> 9 </parent> 10 <modelVersion>4.0.0</modelVersion> 11 <artifactId>springboot-module-web</artifactId> 12 13 <dependencies> 14 <dependency> 15 <groupId>com.springboot.module</groupId> 16 <artifactId>springboot-module-service</artifactId> 17 <version>1.0-SNAPSHOT</version> 18 </dependency> 19 </dependencies> 20 </project>
4. 模块依赖关系图
5. 层说明
springboot-module-api ——业务逻辑接口
springboot-module-model ——实体类
springboot-module-service ——数据访问层,业务逻辑层的实现
springboot-module-util ——工具模块
springboot-module-web ——表现层
6. 包名设计
包名推荐以groupId为开头定义,所有模块的包名结构统一规范,比如groupId是com.springboot.module,而所有模块包名都以com.springboot.module开头,其中web层的WebApplication需要放在com.springboot.module下,不能放在com.springboot.module.web或者com.springboot.module.controller下。推荐使用下面的第一种情况。
6.1. 包名以groupId开头,注意WebApplication.java的位置,必须放在com.springboot.module包下,不能放在com.springboot.module.controller或者com.springboot.module.web包下
6.2. 包名以groupId开头,web层WebApplication.java放在了com.springboot.module.web下。
启动WebApplication.java会报如下错误
6.2.1. 解决方法:
1) 第一步:在WebApplication中加入
1 @ComponentScan(basePackages = {"com.springboot.module"})不是@ComponentScan(basePackages = {"com.springboot.module.*"})
1) 第二步,在springboot-module-service模块中添加ServiceApplication.java类,
6.2.2. 包名不以groupId开头,其他和第一种情况一样也是可以的。但最好推荐是以groupId为开头的
7.只有 web层有application.properties
1 server.port=8086 2 server.servlet-path=/ 3 spring.resources.static-locations=classpath:/static/,classpath:/templates/ 4 spring.mvc.view.suffix=.html 5 6 #配置数据源 7 spring.datasource.driver-class-name=com.mysql.jdbc.Driver 8 spring.datasource.url=jdbc:mysql://localhost:3306/springboot-module 9 spring.datasource.username=root 10 spring.datasource.password=root 11 spring.jpa.hibernate.ddl-auto=update 12 spring.jpa.show-sql=true 13 14 #在控制台输出彩色日志 15 spring.output.ansi.enabled=always
转载于:https://www.cnblogs.com/jcjssl/p/9380309.html
springboot基于maven多模块项目搭建(直接启动webApplication)相关推荐
- Springboot+Mybatis+Druid+Maven多模块项目搭建遇到的各种吭
Springboot+Mybatis+Druid+Maven多模块项目搭建 这里记录一下搭建多模块遇到的吭 首先建立一个父级空项目,在pox里修改下配置 2,建立DaoMapper层和ModelEnt ...
- Maven多模块项目搭建
要: Maven多模块项目搭建,可以通过合理的模块拆分,实现代码复用,便于维护管理,可以根据需要配置指定的模块. __kindeditor_temp_url__ http://git.oschin ...
- ajax动态加载公共模块,Maven多模块项目搭建+SSM框架整合(四、Ajax异步获取数据,jq动态添加)...
最近有点小忙,但是还是在晚上抽出来点时间更新文章,希望对初学者有帮助(都是从那时候过来的,哈哈)一起努力. 开始正题~~~~ 封装类ResultVo 在与前台页面交互的过程中我们一般会用到一个封装类, ...
- 搭建空的maven多模块项目架构并且上传到远程git仓库(超详细 cmd命令版本)
2019独角兽企业重金招聘Python工程师标准>>> 首先看标题分为二部分 搭建空的maven多模块项目 上传到远程git远程仓库 第一步详细教程: 一: 二: 注意点:记住什么都 ...
- SpringBoot+Maven 多模块项目的构建、运行、打包实战
https://www.jb51.net/article/140772.htm?proxy=1 这篇文章主要介绍了SpringBoot+Maven 多模块项目的构建.运行.打包实战,小编觉得挺不错的, ...
- 【sprinb-boot】maven 多模块项目:单独 spring-boot:run 某个模块
目录 前言 假设的 maven 多模块项目 模块关系1 模块关系2 模块关系3 模块关系4 示例:模块关系1 1,my-parent1/pom.xml 文件 2,my-parent1/my-app1/ ...
- maven多模块项目部署到服务器,GitHub - baxias/foweb: 一个基于 Spring+SpringMVC+Mybatis 的Maven多模块项目。(实现前后端分离的服务器端)...
Foweb Framework A multi-modules maven project base on Spring+SpringMVC+Mybatis. 一个基于 Spring+SpringMV ...
- 解决springboot maven多模块项目打包的时候某个被依赖的模块报错找不到main class
springboot maven 多模块项目打包的时候某个被依赖的模块报错 [ERROR] Failed to execute goal org.springframework.boot:spring ...
- IDEA下Maven多模块项目介绍和搭建
为什么80%的码农都做不了架构师?>>> 1Maven多模块项目介绍 为了便于演示和表达,在intellij中建了小项目进行举例,如下图所示 其中web-m2模块,依赖于com ...
最新文章
- LLVM Backend技术
- update 改写 merge into
- python中列表和集合_15个例子掌握Python列表,集合和元组
- 编写和调试Shader程序(1)
- R 语言聚类关联规则
- LeetCode Shell 194. 转置文件
- P4867-Gty的二逼妹子序列【平衡结合,莫队,分块】
- 《Windows服务器配置与管理》远程桌面管理
- Linux select/poll/epoll
- 2014年即将过去,2015年即将到来
- 苹果“撞上”反垄断,围墙花园能否坚挺?
- Android资源下载
- 配电网重构知识及matlab实现
- TODO:这是一个我的自媒体
- 广告词 android,广告语猜猜看
- 计算机老师教育感言,教育信息技术培训心得感言
- 期货手续费怎么计算?
- 联想机架式服务器安装文档,联想智能超算平台LiCO安装手册.docx
- 高德地图坐标的获取( JavaScript API )
- GitHub 上的一个开源项目,可快速生成一款属于自己的手写字体!
热门文章
- tensorflow tuner 调参,示例代码(jupyter notebook 版)
- 3.推荐系统(矩阵分解)
- 人群分割--Fully Convolutional Neural Networks for Crowd Segmentation
- 目标检测--Enhancement of SSD by concatenating feature maps for object detection
- Python-PyCharm 报错解决:ImportError: cannot import name 'InteractiveConsole' from 'code'
- qq说说时间轴php实现,PHP实现时间轴函数
- java读avro的流_0016-Avro序列化反序列化和Spark读取Avro数据
- @NotNull JSR-303验证
- C++_类和结构体所占内存大小,静态成员问题
- hbase建索引java api_hbase java api样例(版本1.3.1,新API)