Sobes.tech
Middle

What is the difference between Spring Boot and Spring Context?

sobes.tech AI

Answer from AI

The Spring Context is the core of the Spring framework, providing a container for managing beans (ApplicationContext). It is responsible for:

  • Creating and configuring beans.
  • Managing their lifecycle.
  • Dependency injection.
  • Detecting annotations (@Component, @Service, etc.).
  • Providing standard services (such as internationalization, event publication).

Spring Boot is a framework built on top of Spring that simplifies the development of standalone, production-ready applications. It is based on the principle of "convention over configuration" and offers:

  • Auto-configuration: Automatically configures your application based on added dependencies.
  • Embedded web server: Uses Tomcat, Jetty, or Undertow by default.
  • Starter dependencies: Sets of dependencies that simplify connecting to various technologies (web, data, security, etc.).
  • Metrics and monitoring: Support for health checks, metrics, and other features via Spring Boot Actuator.

The difference is that the Spring Context provides the basic framework capabilities, while Spring Boot builds on this foundation and adds functionality for quickly creating ready-to-deploy applications with minimal manual configuration. Spring Boot always uses the Spring Context.

Example of initializing Spring Context (without Spring Boot):

// Initializing ApplicationContext by reading XML configuration
ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
MyService service = context.getBean("myService", MyService.class);
service.doStuff();

Example of a Spring Boot application:

// Using SpringBootApplication to run the application
@SpringBootApplication
public class MyApplication {

    public static void main(String[] args) {
        SpringApplication.run(MyApplication.class, args);
    }
}
What is the difference between Spring Boot and Spring… - sobes.tech