How to Create Spring Boot Project in STS

Hello Friends,

We already saw in the tutorial  How to Create Spring Boot Project using Spring Initializer.

In this tutorial, we will see step by step, how we can create a Spring Boot project in sts(Spring Tool Suite).


Step 1:

Download Spring tool suite, if you don't have already from the following link for your respective operating system :

https://spring.io/tools/sts/all

Step 2 :

Extract and Open Spring tool suite by click on its icon, which looks like as below


Step 3:

Choose the path where you want to create Workspace and click on Launch.



Step 4:

Spring tool suite will be launched with the following screen :


Step 5 :

Right-click in the package explorer and select New -> Spring Starter Project as below :


Step 6 :

Next screen that will show up is the following :


Step 7 :

In the screen mentioned in Step 6, we can Change the  "Name" to whatever name we want to give to our project. Also, we can change group id, artifact and package name.

I am going to change to following :

Name : springToolSuiteProject
Group : nl.blogspot.javasolutionsguide
Artifact : springToolSuiteProject
Package :nl.blogspot.javasolutionsguide. springToolSuiteProject

Leave following as is :

Service Url : https://start.spring.io

Type: Maven
Note: If you want to use Gradle as a build tool, then you are free to choose Gradle.

Packaging: Jar
Note: Can be changed to War as per requirement.

Java Version: 8
Note: Can be changed to 10 as well as of writing this tutorial.


Step 8 :

Click Next and we will see the following screen :


Step 9 :

As of writing this tutorial, the Latest release version of Spring Boot is 2.0.3, which is selected by default, so leave it as is.

Add dependencies as per requirement. I am going to add only Web here.


Step 10 :

Click Finish. As you can see in the following screenshot, a Maven project with name springToolSuiteProject is added in the STS :


Step 11 :

Let us expand this project and see what Spring Boot has added to it.

As we can see in below screenshot, Spring boot has added lots of required dependencies on its own.


Before the introduction of Spring Boot, we have to add all these dependencies on our own and considering compatibility between different jar versions, it was really chaotic thing, but now we need not worry about it. Spring Boot takes care of all necessary dependencies. We just need to tell Spring Boot only at a high level that which kind of dependencies we want to add, just like in this case we told spring boot about adding Web dependencies and Spring Boot will add all web related dependencies along with other core dependencies.

Following is how pom.xml of this project looks like :



Following dependencies are added in POM for a standard Spring Boot project, even when we have not added any additional dependencies(example Web).


spring-boot-starter-parent makes sure that all necessary basic Spring dependencies are added,as can be seen in below screenshot : 





spring-boot-starter-web dependency is added additionaly as we selceted Web dependency while creating project.



On adding spring-boot-starter-web, we can see that lots of additional dependencies which are required for web project are added to the build path. This includes embedded tomcat dependencies as well, such that we need not install and configure Tomcat separately to deploy Spring Boot application:



Also, Spring Boot has added the following class, which acts as a starting point for the Spring Boot Application.


- The @SpringBootApplication annotation used at the class level above is basically equivalent to combined following three annotations :

@Configuration
@EnableAutoConfiguration
@ComponentScan

- From the main method of 
SpringToolSuiteProjectApplication, SpringApplicaiton class's run method is called. This method makes sure that Spring application's applicationContext(the Spring Container) is initialized. Spring boot uses AnnotaionConfigApplicationContext.

Step 12 :

Run the main method of SpringToolSuiteProjectApplication and you will notice that jar is automatically deployed to embedded Tomcat server and Tomcat server has been started at port 8080.

Check Console log of eclipse:


With this,we saw that How we can Create a Spring Boot Project in sts tool and how we can deploy and run it on embedded Tomcat server.

Thanks for reading.if it helped you,share it with others to help others.