Home » Spring Maven Project

Spring Maven Project

by Online Tutorials Library

Spring Boot Project

There are multiple approaches to create Spring Boot project. We can use any of the following approach to create application.

  • Spring Maven Project
  • Spring Starter Project Wizard
  • Spring Initializr
  • Spring Boot CLI

Here for all the example, we are using STS (Spring Toll Suite) IDE to create project. You can download this IDE from official site of Spring framework.


Spring Boot Maven Project

Creating Spring Boot project by creating maven project. It includes the following steps.

1) Select project type.

Spring Boot project 1 Spring Boot project 2

Configure project by providing project name.

Spring Boot project 3

After clicking finish, Spring boot project has been created. Our new project looks like the following screen shot.

Spring Boot project 4

This Maven project has a pom.xml file which contains the following default configuration.

// pom.xml

We need to configure it in order to make it a Spring Boot project. Here, we are adding parent to our Maven project. It is used to declare that our project is a child to this parent project.

After that add the following dependency to the pom.xml file. Here, we are adding web dependency by adding spring-boot-starter-web.

Note – Maven project will add web dependency to the project by downloading the jar.

After that add Java version for the project.

Now, our project should have the following directly structure. You can notice that maven has created a new dependency folder to store the jar files.

Spring Boot project 5

Update Maven project each time after including new dependencies.

Spring Boot project 6 Spring Boot project 7

After updating Maven. Now, let’s make it runnable. Create a Java class inside the src/main/java package.

Spring Boot project 8

After creating class call the static run method of SpringApplication class. In the following code, we are calling run method and passing class name as argument.

// SpringBootExample.java

Now, run this class as a Java Application.

Spring Boot project 9

It displays the following output.

Spring Boot project 10

The line Started SpringBootExample in 14.047 seconds (JVM running for 17.391) in output window shows that our application is started.


You may also like