HuntExams Academy logo
JavaIntermediate#spring

What is the difference between Spring Boot and Spring Framework?

Answer

Spring is the core ecosystem (DI, AOP, MVC). Spring Boot is an opinionated layer on top with auto-configuration, embedded servers, and starter dependencies for fast bootstrapping.

Example

// Spring Boot
@SpringBootApplication
public class App {
  public static void main(String[] args) { SpringApplication.run(App.class, args); }
} // no XML config, embedded Tomcat included

Detailed explanation

Spring Framework provides the core programming and infrastructure model for Java applications. Its main features include dependency injection through the IoC container, aspect-oriented programming, transaction management, and web development through Spring MVC or WebFlux. Dependency injection lets the container create objects, called beans, and connect their dependencies instead of application code constructing everything directly. Spring Boot builds on Spring Framework; it is not a replacement or a competing framework. The main difference is that Spring provides the foundational capabilities, while Boot simplifies configuring, assembling, and running applications that use them.

With Spring Framework alone, developers typically make more explicit choices about dependencies, bean configuration, web infrastructure, and deployment. Configuration can use Java classes and annotations, so XML is not mandatory. Spring Boot supplies opinionated defaults through auto-configuration and convenient starter dependencies. For example, spring-boot-starter-web brings together commonly needed dependencies for a Spring MVC application, including embedded Tomcat by default. Boot's dependency management supplies compatible versions for supported libraries, reducing the need to select each version manually. However, an embedded web server is not included in every Boot application; it depends on the dependencies you choose.

Under the hood, @SpringBootApplication combines @SpringBootConfiguration, @EnableAutoConfiguration, and @ComponentScan. SpringApplication.run creates and refreshes the application context and, for an appropriately configured web application, starts the embedded server. Auto-configuration uses conditions based on factors such as classes available on the classpath, configuration properties, and existing beans. For example, an auto-configured bean often backs off when you define your own matching bean. This means Boot provides defaults while still allowing explicit configuration, rather than removing the need to understand Spring.

Boot also offers externalised configuration and optional production-oriented capabilities through Actuator, including health and metrics endpoints. Applications commonly run as executable JARs, although supported servlet applications can also be packaged as WARs for external containers. In interviews, emphasise the relationship: both use Spring's container and programming model, but Boot reduces setup and standardises common choices. Strong answers explain conditional auto-configuration and avoid claiming that Boot requires no configuration or that plain Spring requires XML.

Key points to remember

  • Spring Framework provides core capabilities such as DI, AOP, transactions, and Spring MVC.
  • Spring Boot builds on Spring Framework with opinionated defaults and simpler application startup.
  • Starters group dependencies; Boot dependency management supplies compatible library versions.
  • Auto-configuration applies conditionally and can be customised, replaced, or excluded.
  • Embedded servers, executable JARs, externalised configuration, and optional Actuator support simplify running applications.

Common mistakes candidates make

  • Saying Spring Framework requires XML, although it supports Java-based and annotation-based configuration.
  • Claiming every Spring Boot application includes Tomcat; server availability depends on the chosen dependencies.
  • Treating Boot as a replacement for Spring or assuming auto-configuration eliminates all manual configuration.

Likely follow-up questions

What exactly does @SpringBootApplication do?

It combines @SpringBootConfiguration, @EnableAutoConfiguration, and @ComponentScan. By default, component scanning covers the annotated class's package and its subpackages, so place the application class in an appropriate root package.

How can you override Spring Boot auto-configuration?

You can set configuration properties, define your own beans, or exclude specific auto-configuration classes. Many default beans use conditions such as @ConditionalOnMissingBean, allowing your bean to replace the default where that condition applies.

Can Spring Framework be used without Spring Boot?

Yes, you can create and configure a Spring application context directly using Java configuration, annotations, or XML. Boot is optional; it mainly reduces setup effort and provides conventions for dependency management, configuration, and startup.

Interview tip: Start with 'Spring provides the foundation; Boot simplifies using it,' then explain starters and conditional auto-configuration using the web starter example.

Related Interview Questions

1
JavaIntermediate#jpa

What is JPA vs Hibernate?

Open
2
JavaIntermediate#fundamentals

What is the difference between == and .equals() for Integer in Java?

Open
3
JavaBeginner#fundamentals

What are Java's primitive data types?

Open