Create Parent Module
- Open terminal, navigate to the place you want to create the project and run the following command:
mvn archetype:generate -DgroupId=[GROUP_ID(ie com.nutsnet)] -DartifactId=[ARTIFACT_ID(ie nutsnetservices)] -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.4 -DinteractiveMode=false
Open IntelliJ, Open the created project. Then go to File > Project Structure to make sure the Java version is what you want.
Delete the src folder which is auto generated by maven. Because here is the parent directory of our project, we will create our microservices under this parent directory .
Open pom.xml. Set the project's website url and java compile version.
Get rid of all original dependencies and plugins, and finally, our pom.xml file will be like the following:
<?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.test</groupId>
<artifactId>testservices</artifactId>
<version>1.0-SNAPSHOT</version>
<name>testservices</name>
<url>http://www.test.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
<dependencyManagement>
<dependencies>
</dependencies>
</dependencyManagement>
<dependencies>
</dependencies>
<build>
<pluginManagement>
<plugins>
</plugins>
</pluginManagement>
</build>
</project>
- Now let's start adding dependencies and plugins that we want.
For the dependencyManagement tag, add
spring-boot-dependencies
.For the dependencies tag, we need
lombok
andspring-boot-starter-test
For the pluginManagement tag, add
spring-boot-maven-plugin
.
<?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.test</groupId>
<artifactId>testservices</artifactId>
<version>1.0-SNAPSHOT</version>
<name>testservices</name>
<url>https://www.test.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<spring.boot.maven.plugin.version>2.5.7</spring.boot.maven.plugin.version>
<spring.boot.dependencies.version>2.5.7</spring.boot.dependencies.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring.boot.dependencies.version}</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring.boot.maven.plugin.version}</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
- Click the reload maven project button.
Then we can see the dependencies and plugins are loaded successfully.
Create Microservices
Click New Module, enter the module(service) name, select JDK version, and parent module. Then click Create.
Now in the parent module's pom.xml, we can see the created sub-module(service) is in the module tag.
In the sub-module's pom.xml, we can also see the parent tag specify its parent module and the artifactId tag of the sub-module.
- Add
spring-boot-starter-web
to the sub-module, and click reload maven project.
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
Let's create a Spring Boot banner. (Optional)
Go to https://devops.datenkollektiv.de/banner.txt/index.html and copy the generated banner text.
Back to IntelliJ, Create banner.txt, and paste the banner text.
Run the spring boot application. Now our first service is running successfully !!
We can keep adding other services like this first service.
Top comments (0)