Step-by-Step Guide to Building a Spring Cloud Alibaba Hello World Project
This tutorial walks you through creating a Spring Cloud Alibaba project from scratch using IntelliJ IDEA and Maven, covering parent project setup, module creation, pom.xml configuration, a simple Spring Boot application, a Hello World controller, and how to run and verify the service.
Spring Cloud Alibaba is a subproject of Spring Cloud that provides an all‑in‑one solution for distributed service development. This guide demonstrates how to create a basic Spring Cloud Alibaba project using IntelliJ IDEA and Maven.
Creating the parent project – The parent pom manages version dependencies and sub‑modules. In IDEA select File → New Project → Maven without an archetype, then fill in the project name, GroupId, ArtifactId, and version.
The generated <?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>com.fullstack</groupId> <artifactId>fs-parent</artifactId> <version>1.0-SNAPSHOT</version> <packaging>pom</packaging> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.6.13</version> <relativePath/> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <java.version>1.8</java.version> <spring.cloud.version>2021.0.5</spring.cloud.version> <spring.cloud.alibaba.version>2021.0.5.0</spring.cloud.alibaba.version> </properties> <dependencyManagement> <dependencies> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-alibaba-dependencies</artifactId> <version>${spring.cloud.alibaba.version}</version> <type>pom</type> <scope>import</scope> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>${spring.cloud.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> </project> defines the parent pom.
Creating a sub‑module (fs‑user) – Right‑click the parent project, choose New → Module , select Maven, and confirm GroupId and ArtifactId. The sub‑module pom.xml looks like:
<?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"> <parent> <artifactId>fs-parent</artifactId> <groupId>com.fullstack</groupId> <version>1.0-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>fs-user</artifactId> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.8</source> <target>1.8</target> <encoding>UTF-8</encoding> </configuration> </plugin> </plugins> </build> </project>
In the fs-user module, add a Spring Boot entry class:
package com.fullstack.commerce.user; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class UserApplication { public static void main(String[] args) { SpringApplication.run(UserApplication.class, args); } }
Then create a simple controller to verify the setup:
package com.fullstack.commerce.user.controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController @RequestMapping("hello") public class HelloController { @GetMapping("test") public String test() { return "Hello World"; } }
Run the application and open http://localhost:8080/hello/test in a browser; you should see the text Hello World , confirming that the basic Spring Cloud Alibaba project is successfully built.
The article concludes by noting that this simple Hello World project will serve as a foundation for future enhancements such as service registration, circuit breaking, and other cloud‑native features.
Full-Stack Internet Architecture
Introducing full-stack Internet architecture technologies centered on Java
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.