IDEA搭建SpringBoot项目 connect timed out 错误
在新建 springboot 项目时默认使用的是 start.spring.io 地址,修改自定义方式,地址改为https://start.aliyun.com
| 对比项 | 阿里云 SpringStart( springstart.aliyun.com ) | 官方 Spring Initializr(start.spring.io) |
|---|---|---|
| 核心功能 | ✅ 一样,都是生成 Spring Boot 脚手架项目 | ✅ |
| 网络速度 | 🚀 更快,尤其是在中国大陆 | 🌍 常常较慢甚至超时 |
| 依赖仓库 | 使用阿里云 Maven 镜像,加速依赖下载 | 使用 Maven Central,国内较慢 |
| Spring Boot 版本 | 通常比官方稍落后一两个版本 | 官方发布即更新 |
| 第三方依赖支持 | 有可能缺少最新依赖或 Starter | 全面、官方第一时间支持 |
| 自定义公司脚手架 | 支持阿里巴巴内部 starter,如 Sentinel 等 | 官方纯净版 |
| 可用性 | 稳定、高可用、适合国内团队 | 有时访问困难(需科学上网) |
spring-boot-starter-parent 做了两件大事
spring-boot-starter-parent 是 Spring Boot 提供的 官方父项目(parent POM) ,它就像一个“模板”或“指导手册”,帮助你的项目快速配置好各种依赖、插件、构建策略。
| 作用 | 说明 |
|---|---|
① ** 指定了 spring-boot-starter-web(等众多依赖)的版本** |
它通过 dependencyManagement 统一管理了 Spring Boot 生态内各种依赖的版本,包括但不限于 spring-boot-starter-web、spring-core、jackson、tomcat 等。你在子模块中引入依赖时不需要写 |
| **② ** 配置好了一整套常用的构建插件 |
它默认集成并配置了如 maven-compiler-plugin、maven-surefire-plugin、spring-boot-maven-plugin 等,让你省去很多繁琐的 build/plugins 配置。 |
dependencyManagement vs dependencies
| 特点 | ||
|---|---|---|
| 是否自动引入依赖 | ❌ 不会 | ✅ 会 |
| 是否需显式声明 | ✅ 是 | ❌ 否(只要声明就有效) |
| 用途 | 管理依赖版本、范围、排除等 | 实际引入依赖 |
| 常见位置 | 父模块的 POM | 所有模块的 POM |
-
<dependencies>:就是 "我要用这个依赖!" -
<dependencyManagement>:是 "这些依赖我先帮你把版本配好了,用的时候不用再指定版本。"
比如父模块中的 pom.xml 文件:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>6.1.2</version>
</dependency>
</dependencies>
</dependencyManagement>在子模块中这样子使用父模块:
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<!-- 没有写 version 也能识别出版本 -->
</dependency>
</dependencies>💡 这样做的好处是:
-
项目中各个模块使用的是同一个版本,避免版本冲突;
-
万一要升级版本,只改父 POM 一处就够了。
-
父模块的
<dependencies>不会自动 "注入" 子模块中,只有在子模块手动写<dependency>时才真正使用,版本可以从父模块的<dependencyManagement>中自动继承 。
scope作用域
| Scope | 编译时 | 运行时 | 是否打包进 JAR | 典型用途 |
|---|---|---|---|---|
| compile | ✅ | ✅ | ✅ | 核心库、业务依赖 |
| runtime | ❌ | ✅ | ✅ | JDBC 驱动、SPI 库 |
| provided | ✅ | ❌ | ❌ | 容器提供的库(Tomcat) |
| test | ✅ | ❌ | ❌ | 单元测试库 |
| import | ❌ | ❌ | ❌ | BOM 版本管理 |