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 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!!!
Spring Boot Related Topics
- Introduction to Spring Boot
- Essentials and Key Components of Spring Boot
- Spring Boot CLI Installation and Hello World Example
- Spring Boot Initializr Web Interface
- Spring Boot Initializr With IDEs
- Spring Boot Initializr With Spring Boot CLI
- Installing Spring Boot
- Developing your first Spring Boot application
- External Configurations for Spring Boot Applications
- Logging Configuration in Spring Boot
- Spring Boot and Spring MVC
- Working with SQL Databases and Spring Boot
- MySQL Configurations
- Spring Data JPA using Spring Boot Application
- Spring Boot with NoSQL technologies
- Spring Cache Tutorial
- Spring Security Tutorial with Spring Boot
- Spring Boot and MongoDB in REST Application
- Complete Guide for Spring Boot Actuator
- Microservices with Spring Boot