Spring Boot Initializr with IDEs (via Spring Tool Suite)

Hello friends lets discuss another important components Spring Boot Initializr of Spring Boot, it is a quick way to create spring boot project structure. In this article we are going to explore about Spring Boot Initializr with STS IDE. Spring Boot Initializr is used to quick start new Spring Boot Maven/Gradle projects within no time. It generates initial project structure and builds scripts to reduce Development time.Spring Tool Suite3 has long been a fantastic IDE for developing Spring applications. Since version 3.4.0 it has also been integrated with the Spring Initializr, making it a great way to get started with Spring Boot.

Related tutorials previously we have discussed

Create a new Spring Boot application in Spring Tool Suite


Step 1: Select the New > Spring Starter Project menu item from the File menu.

Step 2: We will get the following “Spring Starter Project” Wizard to provide our project related information.

Step 3: Please provide our Spring MVC Maven Web Application Project details as shown below and Click on “Next” Button

Step 4: Click on “Finish” button to create our new Spring Boot Project.

Step 5: Now Spring STS Suite creates a Maven Project and downloads all required Jars to our Maven Local Repository.

Step 6: Once the project has been imported into your workspace, you’re ready to start developing your application.

Step 7: Execute Spring Boot Application Run As > Spring Boot Application from the Run menu.

Step 8: Access our Spring MVC application with “http://localhost:8080/MySpringBootApp” and observe the results

SpringApplication:

The SpringApplication class provides a convenient way to bootstrap a Spring application that will be started from a main() method. In many situations you can just delegate to the static

SpringApplication.run method:
  • SpringApplication is one of the Spring Boot API classes.
  • SpringApplication class is used to bootstrap a Spring application that will be started from a main() method
package com.dineshonjava;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class MySpringBootAppApplication {

 public static void main(String[] args) {
  SpringApplication.run(MySpringBootAppApplication.class, args);
 }
}

MySpringBootAppApplication class is annotated with @SpringBootApplication annotation.

@SpringBootApplication does the following things:

  • Because of @Configuration annotation, It scans for @Bean methods to create beans.
  • Because of @ComponentScan annotation, It does component scanning (Components means Beans annotated with @Component,@Service,@Repository,@Controller etc).
  • Because of @EnableAutoConfiguration annotation, It triggers Spring Boot Auto-Configuration.

When we run MySpringBootAppApplication class main() method, it make a calls to “SpringApplication.run()” method. Then this call done following things

  • This call is used to create “AnnotationConfigEmbeddedWebApplicationContext”.
  • This “AnnotationConfigEmbeddedWebApplicationContext” instance is used to create an instance of “TomcatEmbeddedServletContainerFactory” class.
  • This “TomcatEmbeddedServletContainerFactory” is used to create an instance of “TomcatEmbeddedServletContainer” class.
  • TomcatEmbeddedServletContainer” instance starts a Tomcat Container at default port number: 8080 and deploys our Spring Boot WebApplication.

Summary

Congratulation!!! Here we have learned how to create Spring Boot Application with Spring Boot Intilizr via STS IDE. And also discussed code flow of run this spring boot application.

Happy Spring Boot Learning!!!

 

Previous
Next