IT Log

Record various IT issues and difficulties.

Setting Up Spring Cloud Project


Contents

Project Setup

Build Parent-Child Projects

Create Parent Project

Spring Cloud Version

Create Child Project – Order Service

Declare Project Dependencies and Build Plugins

Create Child Project-Product Service

Declare Project Dependencies and Build Plugins


Project Setup

Since the application has been split into microservices, multiple projects need to be created. However, IDEA can only have one project per window. To solve this issue, we use parent-child projects.

Building Parent and Child Projects
Creating the Parent Project
1.
Create an empty Maven project, remove all code, and keep only the pom.xml file.
2. Complete the pom file
Use properties for unified version management, use dependencyManagement to manage dependencies, and declare the parent project’s packaging type as pom.

DependencyManagement and Dependencies:

1. dependencies: Adds the dependent jar directly to the project, with subprojects inheriting this dependency.
2. dependencyManagement: Only declares dependencies without implementing jar package inclusion. If subprojects need related dependencies, they must explicitly declare them. If subprojects do not specify a version, they will read it from the parent project. If subprojects specify a version, the specified jar version in the subproject will be used. Additionally, the packaging of the parent project should be pom, not jar; here, manual declaration with packaging is required.

Spring Boot manages versions of dependent jar packages using this approach as well

Version determination of dependent jars

In the above code, lombok will be directly introduced into the current project and sub-projects. However, mysql-connector-j will not actually introduce the jar file; explicit declaration is required when sub-projects inherit.

Spring Cloud Version

Spring Cloud is built on top of Spring Boot, so the version of Spring Cloud is related to the version of Spring Boot.

Creating Sub-projects – Order Service

Declaring Project Dependencies and Build Plugins

Create Subproject – Product Service



5 responses to “Setting Up Spring Cloud Project”

  1. This article simplified the process of setting up multiple microservices under one project. The use of Maven plugins and dependency management was explained clearly.

  2. Thanks to this guide, I now understand better how dependency management works in multi-module Spring projects. Highly recommended for developers!

  3. I found the part about creating parent and child projects particularly helpful. It clarified how to structure multiple services within a single IntelliJ IDEA window.

  4. The article does an excellent job explaining how to manage dependencies and plugins in parent-child projects. It’s a must-read for anyone working with Spring Boot and Spring Cloud!

  5. This article is a perfect guide for setting up Spring Cloud projects, especially useful for those new to microservices architecture. The step-by-step instructions make it easy to follow and understand.

Leave a Reply