参考文档:
大致原理性的参考文档:
https://blog.csdn.net/DerekSu/article/details/107151431
官方创建实例参考文档:
https://docs.spring.io/initializr/docs/current-SNAPSHOT/reference/html/
为什么要搭建
- 因为网络不好,start.spring.io访问超时
- 需要定制一些依赖,加入团队专属的依赖
- 加入新的依赖,以便创建新项目,重新编写项目的pom.xml文件
搭建步骤:
下载源码:
Spring Initializr本来就是有实现的源码的
我们并不需要下载Spring Initializr的源码,而是要下载它集成的项目start.spring.io
https://github.com/spring-io/start.spring.io
这个项目只有master,没有稳定版,但是经过验证,这个是可用的,之后有稳定版建议下载稳定release版。
故 使用 git clone 或者直接下载zip包都行
git clone https://github.com/spring-io/start.spring.io.git
用IDEA打开:
下载完之后可以使用idea打开:
项目结构如下:

说明:
- 如果不需要使用网页创建项目的话,前端是不需要的
- 后端启动就完全能支持IDE的使用。
配置文件说明
配置java版本:
initializr:
javaVersions:
- id: 14
default: false
- id: 11
default: false
- id: 1.8
name: 8
default: true #默认创建的maven项目是1.8
配置maven打包的方式:
initializr:
packagings:
- name: Jar
id: jar
default: true # 默认是jar包
- name: War
id: war
default: false
配置springboot版本:
initializr:
bootVersions:
- name : Latest SNAPSHOT #版本名称
id: 2.2.0.BUILD-SNAPSHOT # 具体版本号
default: false
- name : 2.1.1.
id: 2.1.1.RELEASE
default: true # 是否是默认的
配置默认的groupId
,artifactId
,name
,description
,versionpackageName
.
initializr:
group-id:
value: org.acme
artifact-id:
value: my-app
配置maven项目的结构:
initializr:
types:
- name: Maven Project
id: maven-project # 如果是maven project,生成的项目会有main,resource等目录结构
description: Generate a Maven based project archive.
tags:
build: maven
format: project
default: true
action: /starter.zip
- name: Maven POM
id: maven-build # 如果是maven pom,生成的项目不会有main,resource等目录结构,只有一个pom文件
description: Generate a Maven pom.xml.
tags:
build: maven
format: build
default: false
action: /pom.xml
- name: Gradle Project
id: gradle-project
description: Generate a Gradle based project archive.
tags:
build: gradle
format: project
default: false
action: /starter.zip
- name: Gradle Config
id: gradle-build
description: Generate a Gradle build file.
tags:
build: gradle
format: build
default: false
配置依赖:
initializr:
dependencies:
- name: XinfengWei Dependencies # 配置依赖的一级分类
content:
- name: Fast Json Util # 配置依赖的二级分类,这里配置的是具体依赖,一级分类下有多个就配置多个
id: fast-json-util
groupId: com.xfw.util
artifactId: fastJsonUtil
scope: runtime # 配置依赖的scope
description: XinFengWei FastJson Utils # 依赖的描述
starter: false #是否是starter
version: 1.2.3-RELEASE # 指定依赖的版本
links: # 配置连接
- rel: reference
href: https://docs.spring.io/spring-boot/docs/{bootVersion}/reference/htmlsingle/#using-boot-devtools
- name: Fast Json Util # 配置依赖的二级分类,这里配置的是具体依赖
id: fast-json-util
groupId: com.xfw.util
artifactId: fastJsonUtil
scope: runtime
description: XinFengWei FastJson Utils
starter: false
version: 1.2.3-RELEASE # 指定依赖的版本
links:
- rel: reference
href: https://docs.spring.io/spring-boot/docs/{bootVersion}/reference/htmlsingle/#using-boot-devtools
配置完后启动项目
server:
port: 8080
使用StartApplication启动项目:

看到控制台大致有下面的信息就启动成功了

使用自己的spring-initializr创建项目:
win10 IDEA ---->File ----->New ----->Project:

点击next:

这里,你能选择配置的Java版本,maven package类型、语言、制定项目groupid,artifactId、maven项目结构等
继续next:

点击next后指定项目的名称和项目储存地址创建完成。

遵从以上的搭建和测试步骤,你就能成功搭建和定制自己的spring initializr服务了
注意点:
- 以上方式只是初步的完成添加团队依赖,配置语言,java版本,springboot版本。若想要更完善的功能请按照官方文档一步步的说明
- 搭建服务启动后,第一次创建服务很慢,因为涉及到文件io,文件结构解析,而且未加入缓存。但是第二次使用服务就快了
网友评论