Spring vs. Spring Boot: What’s Difference?

Spring Framework and Spring Boot are two popular frameworks for developing enterprise applications in Java. While they both belong to the Spring ecosystem, they serve different purposes and have distinct characteristics.

In this article, we will explore the differences between Spring and Spring Boot, providing a detailed comparison and a tabular overview of their features.

1. Differences between Spring Framework and Spring Boot

The following table gives a detailed comparison between Spring Framework and Spring Boot, including additional features and differences.

FeatureSpring FrameworkSpring Boot
PurposeComprehensive enterprise framework for developing applications using SpringProvides simplified and rapid application development (RAD) features
Framework ComplexityHighLow to Medium
Configuration OptionsXML/Annotation-basedXML/Annotation and application.properties/YAML based
Managing Project DependencyManualAutomatic with use of starter modules
Embedded Web ServerNoYes (Tomcat, Jetty, etc.). The default is Tomcat.
Project Setup ToolsManualSpring Initializer
Convention over Configuration (CoC)LimitedStrong
Auto-ConfigurationNoYes (Auto-configures beans based on libraries detected on the classpath)
External ConfigurationUsing PropertyPlaceholderConfigurerSpring Boot properties placed in application.properties
LoggingExplicit configuration via logback, log4j, etc.Spring Boot Starter for Logging (logback by default)
Database Connection PoolingExplicit manual setup (e.g., Apache DBCP, C3P0)Integrated (HikariCP by default)
Template Engines (e.g., Thymeleaf, FreeMarker)Explicit manual configurationAuto-configured based on included dependencies. Thymeleaf and JSP are automatically configured for web applications.
Microservices SupportRequires additional setup (e.g., Spring Cloud)Built-in support for microservices architecture
Testing SupportExplicit manual configuration (e.g., JUnit 5, TestNG)Spring Boot Starter for Testing (e.g., @SpringBootTest)
Production-Ready FeaturesExplicit manual setup for ActuatorBuilt-in Actuator (metrics, health checks, etc.) by adding the starter module
Aspect-Oriented Programming (AOP)Manual setup of AOPAuto-configuration support for AOP
Security ConfigurationRequires manual setup (e.g., Spring Security)Simplified default security with overridable configurations
Custom Error PagesManual setup (e.g., ErrorController)Simplified error handling with default error pages and custom configuration
Transaction ManagementRequires manual setup (e.g., @Transactional)Auto-configured using @EnableTransactionManagement
Database Access / DataSource ConfigurationExplicit setup for JDBC, JPA, Hibernate, etc.DatSource autoconfiguration with Spring Data Starter with custom configurations
Internationalization (i18n)Manual configuration (e.g., ResourceBundleMessageSource)Auto-configuration for message sources in the classpath
Developer ExperienceSteeper learning curve, more controlFaster development with conventions

2. In-Depth Comparison of Spring vs. Spring Boot

Let us compare some of the above-listed features for a more detailed understanding of how both frameworks differ in their configurations and usages.

2.1. Dependency Management

In the traditional Spring Framework, dependency management is primarily a manual process. Developers are responsible for explicitly declaring and managing dependencies and their versions in their project’s build file.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>spring-project</artifactId>
    <version>1.0.0</version>

    <dependencies>
        <!-- Spring Core -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>5.3.10.RELEASE</version>
        </dependency>

        <!-- Spring Web -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>5.3.10.RELEASE</version>
        </dependency>

        <!-- Other dependencies -->
    </dependencies>

</project>

Spring Boot simplifies dependency management further with “starters.” We only need to manage the version of the parent starter, and rest everything is resolved automatically.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>spring-boot-project</artifactId>
    <version>1.0.0</version>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.1.1</version> <!-- Spring Boot version -->
    </parent>

    <dependencies>
        <!-- Spring Boot Starter for Web -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <!-- Other dependencies -->
    </dependencies>

</project>

2.2. Auto-Configuration

Autoconfiguration is a key feature specific to Spring Boot. It is not present in traditional Spring applications.

For example, in traditional Spring applications, configuring MVC typically involves XML or Java-based configuration for setting up DispatcherServlet, defining controllers, view resolvers, and mapping URL patterns.

@Configuration
@EnableWebMvc
public class MvcConfig implements WebMvcConfigurer {

  @Override
  public void configureViewResolvers(ViewResolverRegistry registry) {
    registry.jsp("/WEB-INF/views/jsp/", ".jsp").cache(true);
  }

  @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
    }
  //...
}

Spring Boot simplifies MVC configuration by providing convention-over-configuration and sensible defaults, just by including the ‘web’ starter module.

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-web</artifactId>
</dependency>

The autoconfiguration included with the above starter, automatically does the following:

  • Configures default view resolvers (Thymleaf and JSP) for resolving view names to templates. 
  • Automatically configures resource handling for static content like CSS, JavaScript, and images.
  • Includes support for different media types, such as JSON, XML, and HTML.
  • Provides default exception handling mechanisms.
  • Provides support for internationalization and theming by configuring message sources and themes.
  • And more.

2.3. Security Configuration

In Spring, we can configure security using Java-based or XML-based configuration, depending on our preference. We define all the security beans and configurations ourselves.

In Spring boot, just by adding the security starter, autoconfiguration configures a number of default security features such as:

  • Create a single user with the username as user and auto-generated password.
  • Auto-configures basic authentication for API access.
  • Sets up a default login form for the web applications.
  • Cross-Site Request Forgery (CSRF) protection is enabled by default to prevent CSRF attacks.
  • Enables monitoring and tracking of security-related activities in the application.
  • Configures session management, session timeout and session fixation protection.
  • Passwords are automatically encrypted using bcrypt by default.
  • And more.

3. Conclusion

The comparison between Spring framework and Spring Boot in this article is based on general characteristics and differences. The choice between them depends on the project’s specific requirements, complexity, and development goals.

Always refer to the official documentation for the most up-to-date information on each framework’s capabilities and features.

Happy Learning !!

Comments

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments

About Us

HowToDoInJava provides tutorials and how-to guides on Java and related technologies.

It also shares the best practices, algorithms & solutions and frequently asked interview questions.

Our Blogs

REST API Tutorial

Dark Mode

Dark Mode