惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
Vulnerabilities – Threatpost
U
Unit 42
F
Fortinet All Blogs
aimingoo的专栏
aimingoo的专栏
P
Proofpoint News Feed
F
Full Disclosure
月光博客
月光博客
Engineering at Meta
Engineering at Meta
博客园_首页
The Register - Security
The Register - Security
G
Google Developers Blog
The Cloudflare Blog
博客园 - Franky
K
Kaspersky official blog
A
Arctic Wolf
Scott Helme
Scott Helme
C
Cisco Blogs
Hugging Face - Blog
Hugging Face - Blog
C
Check Point Blog
NISL@THU
NISL@THU
AI
AI
D
DataBreaches.Net
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Stack Overflow Blog
Stack Overflow Blog
Project Zero
Project Zero
The GitHub Blog
The GitHub Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
量子位
Vercel News
Vercel News
T
Tor Project blog
P
Privacy International News Feed
D
Docker
I
Intezer
L
LangChain Blog
P
Proofpoint News Feed
Security Latest
Security Latest
C
CXSECURITY Database RSS Feed - CXSecurity.com
T
Threatpost
博客园 - 聂微东
AWS News Blog
AWS News Blog
Martin Fowler
Martin Fowler
P
Privacy & Cybersecurity Law Blog
V
V2EX
Last Week in AI
Last Week in AI
C
Cybersecurity and Infrastructure Security Agency CISA
The Hacker News
The Hacker News
T
Tenable Blog
Blog — PlanetScale
Blog — PlanetScale
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
Tailwind CSS Blog

博客园 - 风雨行者

使用 Qjx.CustomCache 在接口进行AOP 数据缓存 asp.net core 基于autofac 实现AOP 拦截 之 第三种方式 -基于class asp.net core 基于autofac 实现AOP 拦截 之 第二种方式 -基于class asp.net core 3.1 应用Aufac 进行AOP 的三种方式1 基于接口AOP linux之 tomcat 安装配置入门 linux的nginx的安装以及负载均衡 linux 系统管理 linux 服务管理 redis主从复制 读写分离 Redis 集群部署之Redis 安装(1) hbuilder 运行在 android 模拟器中 asp.net digest 摘要认证过程 .NET Core CLI 的性能诊断介绍 转载学习:windows下将ES和kibana作为服务启动 转(以作记录):cmd命令行---进行Windows服务操作 在 .NET Core 中使用 Diagnostics MyEclipse 使用外部tomcat 调试springboot Git与GitHub 学习笔记 dropdownlist 支持键盘拼音定位选择
转载:Spring Boot 不使用默认的 parent,改用自己的项目的 paren
风雨行者 · 2020-07-29 · via 博客园 - 风雨行者

在初学spring boot时,官方示例中,都是让我们继承一个spring的 spring-boot-starter-parent 这个parent:

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

  2. <artifactId>spring-boot-starter-parent</artifactId>

  3. <version>1.5.1.RELEASE</version>

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

  5. <artifactId>spring-boot-starter-web</artifactId>

但是,一般情况下,在我们自己的项目中,会定义一下自己的 parent 项目,这种情况下,上面的这种做法就行不通了。那么,该如何来做呢?其实,在spring的官网也给出了变通的方法的:

在我们自己 parent 项目中,加下下面的声明

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

  2. <artifactId>spring-boot-dependencies</artifactId>

  3. <version>1.5.1.RELEASE</version>

请注意,它的 type 是 pom,scope 是 import,这种类型的 dependency 只能在 dependencyManagement 标签中声明。

然后,把我们项目中的 子项目 中,parent 的声明,修改为我们自己项目的 parent 项目就可以了,比如,我的是:

  1. <groupId>org.test</groupId>

  2. <artifactId>spring</artifactId>

  3. <version>0.1-SNAPSHOT</version>

1

有一点,需要注意一下。 
在 子项目 的 dependencies 中,不需要(也不能)再次添加对 spring-boot-dependencies 的声明了,否则 子项目 将无法编译通过。 
即,在 子项目 中,下面的配置是多余的:

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

  2. <artifactId>spring-boot-dependencies</artifactId>

为什么会这个样子呢? 
因为 spring-boot-dependencies 根本就没有对应的jar包,它只是一个 pom 配置,可以去 maven仓库 看一下。 
它里面定义了 非常多 的依赖声明。

所以,有了它之后,我们在 子项目 中使用到的相关依赖,就不需要声明version了,如:

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

  2. <artifactId>spring-boot-starter-web</artifactId>

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

  4. <artifactId>spring-boot-starter-test</artifactId>

如,spring-boot-starter-web 和 spring-boot-starter-test 在 spring-boot-dependencies 中的声明分别为:

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

  2. <artifactId>spring-boot-starter-web</artifactId>

  3. <version>1.5.1.RELEASE</version>

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

  5. <artifactId>spring-boot-starter-test</artifactId>

  6. <version>1.5.1.RELEASE</version>

  7. <groupId>commons-logging</groupId>

  8. <artifactId>commons-logging</artifactId>

参考文档 
spring 官方文档