Junior — Middle
What processes are launched at the start of a Spring Boot application?
sobes.tech AI
Answer from AI
When starting a Spring Boot application, several key stages occur:
- Main method execution —
SpringApplication.run()is called, which initializes the application context. - Creating ApplicationContext — Spring Boot creates and configures the
ApplicationContext(usuallyAnnotationConfigApplicationContextorSpringApplicationContext). - Auto-configuration — classes annotated with
@EnableAutoConfigurationare triggered, configuring beans and components based on dependencies and properties. - Component scanning — Spring scans packages for components with annotations like
@Component,@Service,@Repository,@Controllerand registers them. - Dependency injection — dependencies are injected into beans.
- Execution of CommandLineRunner and ApplicationRunner — if beans implementing these interfaces exist, their
run()methods are called after the context is initialized. - Starting the embedded server (if a web application) — for example, Tomcat or Jetty starts and begins listening for HTTP requests.
Thus, Spring Boot simplifies application configuration and startup, automatically selecting the necessary components and creating a ready-to-run application.