快速开始
三步将 ContiNew Starter 集成到你的 Spring Boot 项目:锁定版本、引入模块、按需配置。
本文是 2.x 的归档文档(冻结于 v2.17.0)。该分支只接收勘误修正, 内容基本不再变动;文中的源码路径、配置项与版本号均以 2.17.x 为准,不建议用于新项目。
新项目请查看 3.x 最新文档。已在 2.17.x 上运行的项目,本文仍是可靠依据。
集成 ContiNew Starter 只需三步:锁定版本、引入所需模块、按需配置。下面以最常用的 web 模块为例。
锁定版本
在 pom.xml 中锁定 ContiNew Starter 版本,两种方式任选其一。
方式一:作为 Parent(替换 Spring Boot Parent)
<parent>
<groupId>top.continew.starter</groupId>
<artifactId>continew-starter</artifactId>
<version>2.17.0</version>
</parent>方式二:导入 Dependencies BOM(替换 Spring Boot Dependencies)
<properties>
<java.version>17</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>top.continew.starter</groupId>
<artifactId>continew-starter-dependencies</artifactId>
<version>2.17.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>示例使用当前版本 2.17.0;升级时把它换成目标版本即可,最新版本可在 Maven Central 查询。
引入所需模块
在 pom.xml 的 <dependencies> 中引入你需要的模块,无需指定版本号(由上面锁定的 BOM 统一供给):
<dependencies>
<!-- Web 模块 -->
<dependency>
<groupId>top.continew.starter</groupId>
<artifactId>continew-starter-web</artifactId>
</dependency>
</dependencies>各模块坐标均为 top.continew.starter:continew-starter-<模块名>,完整模块清单见功能模块。
按需配置
在 application.yml 中按引入的模块添加配置。多数模块提供合理默认值,只需配置你要定制的项。
示例:开启跨域配置
continew-starter:
web:
cors:
enabled: true
allowed-origins: '*' # 允许跨域的域名
allowed-methods: '*' # 允许的请求方式
allowed-headers: '*' # 允许的请求头
exposed-headers: '*' # 暴露的响应头自研配置项以 continew-starter.<模块> 为前缀;对上游框架的扩展沿用对方命名空间(如 application.*、spring.task.*),详见配置约定。完整清单见配置参考。