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.
Configure project by providing project name.
After clicking finish, Spring boot project has been created. Our new project looks like the following screen shot.
This Maven project has a pom.xml file which contains the following default configuration.
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.
Update Maven project each time after including new dependencies.
After updating Maven. Now, let’s make it runnable. Create a Java class inside the src/main/java package.
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.
Now, run this class as a Java Application.
It displays the following output.
The line Started SpringBootExample in 14.047 seconds (JVM running for 17.391) in output window shows that our application is started.