-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating
Spring: Microservices with Spring Boot
By :
Do you want to auto-generate Spring Boot projects? Do you want to quickly get started with developing your application? Spring Initializr is the answer.
Spring Initializr is hosted at http://start.spring.io. The following screenshot shows how the website looks:

Spring Initializr provides a lot of flexibility in creating projects. You have options to do the following:
Group ID and Artifact ID for your component.Switch to the full version, to see all the starter projects you can choose from.The following screenshot shows some of the options Spring Initializr provides when you expand (click on the link) to the full version:

We will use the full version and enter the values, as follows:

Things to note are as follows:
Build tool: MavenSpring Boot version: Choose the latest availableGroup: com.mastering.springArtifact: first-spring-initializrSelected dependencies: Choose Web, JPA, Actuator and Dev Tools. Type in each one of these in the textbox and press Enter to choose them. We will learn more about Actuator and Dev Tools in the next sectionJava version: 1.8Go ahead and click on the Generate Project button. This will create a .zip file and you can download it to your computer.
The following screenshot shows the structure of the project created:

We will now import this project into your IDE. In Eclipse, you can perform the following steps:
pom.xml file)..This will import the project into Eclipse. The following screenshot shows the structure of the project in Eclipse:

Let's look at some of the important files from the generated project.
The following snippet shows the dependencies that are declared:
<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies>
A few other important observations are as follows:
.jarorg.springframework.boot:spring-boot-starter-parent is declared as the parent POM<java.version>1.8</java.version>: The Java version is 1.8org.springframework.boot:spring-boot-maven-plugin) is configured as a plugin
FirstSpringInitializrApplication.java is the launcher for Spring Boot:
package com.mastering.spring;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure
.SpringBootApplication;
@SpringBootApplication
public class FirstSpringInitializrApplication {
public static void main(String[] args) {
SpringApplication.run(FirstSpringInitializrApplication.class,
args);
}
}
FirstSpringInitializrApplicationTests contains the basic context that can be used to start writing the tests as we start developing the application:
package com.mastering.spring;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
public class FirstSpringInitializrApplicationTests {
@Test
public void contextLoads() {
}
}Change the font size
Change margin width
Change background colour