前言
在Idea内新建SpringBoot工程的时候,默认是引入的http://start.spring.io/的接口信息,公司自研工具基础组件包等,每次都要重复引入等,这种重复动作虽简单,但是是一种浪费时间的表现,而且每次包的管理也是一大头疼问题。
参考文献
spring
springinitialzr源码包: 官网仓库 https://github.com/spring-io/initializr/
官网文档:https://docs.spring.io/initializr/docs/current-SNAPSHOT/reference/html/#configuration-guide
本次我下载的是0.12.0版本 项目包结构功能 生成项目
阿里开源
阿里脚手架:https://start.aliyun.com/bootstrap.html?spm=a2ck6.17690074.0.0.6af32e7dt8TBLl
说明: 阿里脚手架相比较于spring的话,额外提供了应用架构传统的分层架构、mvc、以及目前业界流行的DDD(COLA)架构,可惜的是,目前这个项目还没有开源。
自定义Initialzr
基于spring initialzr的做法
在spring initialzr项目中,initialzr-service-sample给了我们sample演示,可直接在此项目基础上演示
- application.yml文件改动
基本配置有groupId, artifactId, name,description dependencies是依赖包的选择项,这里可以根据自己的需求添加相应的java包
initializr:
group-id:
value: org.acme
dependencies:
- name: Web
content:
- name: Web
id: web
description: Servlet web application with Spring MVC and Tomcat
languages:
- name: Java
id: java
default: true
- name: Kotlin
id: kotlin
default: false
- name: Groovy
id: groovy
default: false
javaVersions:
- id: 11
default: true
- id: 1.8
name: 8
default: false
packagings:
- name: Jar
id: jar
default: true
- name: War
id: war
default: false
types:
- name: Maven Project
id: maven-project
description: Generate a Maven based project archive
tags:
build: maven
format: project
default: true
action: /starter.zip
- name: Gradle Project
id: gradle-project
description: Generate a Gradle based project archive
tags:
build: gradle
format: project
default: false
action: /starter.zip
server:
port: 8081
2,启动项目 这里默认端口是8080,最好是自己重定义一下 3,idea新建spring项目 4,设置相应的报名和语言等了 5,依赖包和springboot版本选择
自定义项目
-
新建项目工程 -
pom依赖管理
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>myspring-initializr</artifactId>
<version>1.0-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.4</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.spring.initializr</groupId>
<artifactId>initializr-bom</artifactId>
<version>0.12.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>io.spring.initializr</groupId>
<artifactId>initializr-web</artifactId>
</dependency>
<dependency>
<groupId>io.spring.initializr</groupId>
<artifactId>initializr-generator-spring</artifactId>
</dependency>
</dependencies>
</project>
- application.yml配置
server:
compression:
enabled: true
mime-types: application/json,text/css,text/html
min-response-size: 2048
port: 8082
initializr:
group-id:
value: com.heytap
dependencies:
- name: Web
content:
- name: Web
id: web
description: Servlet web application with Spring MVC and Tomcat
- name: mypackage
content:
- name: demo.Framework
id: demo-core-starter
groupId: com.heytap.mall.demo
artifactId: demo-core-starter
version: 0.1.0-SNAPSHOT
description: Brings first-class support for CQRS, Event Sourcing, and DDD to SpringBoot including Commands, Queries, Aggregates, Events, Event Handlers, and more...
languages:
- name: Java
id: java
default: true
- name: Kotlin
id: kotlin
default: false
- name: Groovy
id: groovy
default: false
javaVersions:
- id: 11
default: false
- id: 1.8
name: 8
default: true
package-name:
value: com.evan.demo,com.evan.api
packagings:
- name: Jar
id: jar
default: true
- name: War
id: war
default: false
types:
- name: Maven Project
id: maven-project
description: Generate a Maven based project archive
tags:
build: maven
format: project
default: true
action: /starter.zip
- name: Gradle Project
id: gradle-project
description: Generate a Gradle based project archive
tags:
build: gradle
format: project
default: false
action: /starter.zip
boot-versions:
- id: 2.3.2-RELEASE
name: 2.3.2
default: true
- idea创建自定义项目
|