Boost Spring Boot Project Generation with Alibaba’s start.aliyun.com and Spring Initializr
This article explains how Alibaba’s start.aliyun.com extends Spring Initializr to provide ready‑to‑use demos, configuration samples and multi‑component integration, covering background, core features, basic usage, YAML configuration, dependency management, version ranges, BOM handling, caching, demo code generation and the underlying startup and generation phases of the framework.
Background
Many developers use start.spring.io to bootstrap Spring Boot projects, which offers a rich set of components and packaging options. Recently, Alibaba's Nacos and Sentinel were added to the options, but the generated skeleton only contains component coordinates without usage examples, requiring developers to search for tutorials and risking version mismatches.
Goal and New Site
To make Alibaba Cloud the most developer‑friendly cloud for Java, the team created start.aliyun.com , which builds on Spring Initializr while adding demo code, configuration samples, and integrated component documentation.
Core Features of start.aliyun.com
Individual demo code and configuration samples for each component.
Built‑in project documentation to reduce the need for external docs.
A “subtract‑instead‑of‑add” approach for component usage.
Multi‑component integration solutions (in development).
Regular updates to keep up with the latest Spring Boot features.
Basic Usage
Include the Initializr BOM in your Maven build:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.spring.initializr</groupId>
<artifactId>initializr-bom</artifactId>
<version>0.9.0.BUILD-SNAPSHOT</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>Then add the required modules, for example:
<dependency>
<groupId>io.spring.initializr</groupId>
<artifactId>initializr-generator-spring</artifactId>
</dependency>
<dependency>
<groupId>io.spring.initializr</groupId>
<artifactId>initializr-version-resolver</artifactId>
</dependency>
<dependency>
<groupId>io.spring.initializr</groupId>
<artifactId>initializr-web</artifactId>
</dependency>Basic Configuration (application.yml)
initializr:
packagings:
- name: Jar
id: jar
default: true
- name: War
id: war
default: false
javaVersions:
- id: 13
default: false
- id: 11
default: false
- id: 1.8
name: 8
default: true
languages:
- name: Java
id: java
default: true
- name: Kotlin
id: kotlin
default: false
- name: Groovy
id: groovy
default: falseProject types can also be defined:
initializr:
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: Maven POM
id: maven-build
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
action: /build.gradleDependency Configuration
Define dependencies under initializr.dependencies with groups and content:
initializr:
dependencies:
- name: Web
content:
- name: Web
id: web
description: Full-stack web development with Tomcat and Spring MVC
- name: Developer Tools
content:
- name: Spring Boot DevTools
id: devtools
groupId: org.springframework.boot
artifactId: spring-boot-devtools
description: Provides fast application restarts, LiveReload, and configurations for enhanced development experience.
- name: Lombok
id: lombok
groupId: org.projectlombok
artifactId: lombok
description: Java annotation library which helps to reduce boilerplate code.Each dependency includes id, groupId, artifactId, name, description and optional version.
Version Ranges
Version ranges use Maven‑style interval notation, e.g. [1.1.6.RELEASE,1.3.0.M1) includes the lower bound but excludes the upper bound. A single version like 1.2.0.RELEASE means that version and any later ones. The x placeholder can be used for the latest release in a series, e.g. 1.4.x.BUILD-SNAPSHOT.
Compatibility Range
When a component’s version depends on the Spring Boot version, use compatibilityRange either directly on the component or inside a mappings block to adjust the artifactId per Boot version.
BOM Management
Define a BOM under initializr.env.boms and reference it in a dependency:
initializr:
env:
boms:
my-api-bom:
groupId: org.acme
artifactId: my-api-dependencies
version: 1.0.0.RELEASE
repositories: my-api-repo-1 initializr:
dependencies:
- name: Other
content:
- name: My API
id: my-api
groupId: org.acme
artifactId: my-api
bom: my-api-bomAdvanced Customization
Enable Caching
Add cache dependencies and annotate the main class with @EnableCaching:
<dependency>
<groupId>javax.cache</groupId>
<artifactId>cache-api</artifactId>
</dependency>
<dependency>
<groupId>org.ehcache</groupId>
<artifactId>ehcache</artifactId>
</dependency>Adding Demo Code
Register a custom ProjectContributor via spring.factories to generate demo files when a specific component is selected:
io.spring.initializr.generator.project.ProjectGenerationConfiguration=\
com.alibaba.alicloud.initializr.extension.dependency.springboot.SpringCloudProjectGenerationConfigurationExample contributor:
@ProjectGenerationConfiguration
public class SpringCloudAlibabaProjectGenerationConfiguration {
private final InitializrMetadata metadata;
private final ProjectDescription description;
private final IndentingWriterFactory indentingWriterFactory;
private final TemplateRenderer templateRenderer;
public SpringCloudAlibabaProjectGenerationConfiguration(InitializrMetadata metadata,
ProjectDescription description,
IndentingWriterFactory indentingWriterFactory,
TemplateRenderer templateRenderer) {
this.metadata = metadata;
this.description = description;
this.indentingWriterFactory = indentingWriterFactory;
this.templateRenderer = templateRenderer;
}
@Bean
@ConditionalOnRequestedDependency("sca-oss")
public OSSDemoCodeContributor ossContributor() {
return new OSSDemoCodeContributor(description, templateRenderer);
}
// ... other contributors
}The contributor renders a Mustache template and writes the generated file to the project directory.
Principles of Spring Initializr
Startup Phase
The application loads configuration, initializes metadata providers, creates the template engine, and registers web endpoints. The main auto‑configuration class is InitializrAutoConfiguration, which sets up beans such as ProjectDirectoryFactory, IndentingWriterFactory, and MustacheTemplateRenderer.
Generation Phase
For each request, a new ProjectGenerationContext (a child of the main application context) is created. The context registers a ProjectDescription provider, configuration classes, and then invokes the ProjectGenerator, which delegates to a series of ProjectContributor implementations to write files such as pom.xml, source code, resources, and documentation.
Extension Points
Two main extension mechanisms are provided:
ProjectContributor : receives the project root path and can write any files (e.g., Maven pom, web folders, application.properties, main class, HELP.md).
Customizer : named components such as MainApplicationTypeCustomizer, BuildCustomizer, GitIgnoreCustomizer, etc., which adjust specific parts of the generated project before files are written.
Reference Links
Initializr documentation
Spring Initializr GitHub
start.spring.io GitHub
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Java Backend Technology
Focus on Java-related technologies: SSM, Spring ecosystem, microservices, MySQL, MyCat, clustering, distributed systems, middleware, Linux, networking, multithreading. Occasionally cover DevOps tools like Jenkins, Nexus, Docker, and ELK. Also share technical insights from time to time, committed to Java full-stack development!
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
