Spring vs. Spring Boot: A Comparison of These Java Frameworks

DZone 's Guide to

Spring vs. Spring Boot: A Comparison of These Java Frameworks

Want to learn more about these two popular Java frameworks? Check out this look at Spring and Spring Boot and how they each solve a different type of problem.

· Java Zone ·
Free Resource

What is Spring Boot? And, what is a Spring Framework? What are their goals? How can we compare them? There must be a lot of questions running through your mind. At the end of this blog, you will have the answers to all of these questions. In learning more about the Spring and Spring Boot frameworks, you will come to understand that each solve a different type of problem.

What Is Spring? What Are the Core Problems Spring Solves?

The Spring Framework is one of the most popular application development frameworks for Java. One of the best features in Spring is that it has the Dependency Injection (DI) or Inversion Of Control (IOC), which allows us to develop loosely coupled applications. And, loosely coupled applications can be easily unit-tested. 

Example Without Dependency Injection

Consider the example below — MyController  depends on MyService  to perform a certain task. So, to get the instance of MyService, we will use:

MyService service = new MyService();

Now, we have created the instance for MyService , and we see both are tightly coupled. If I create a mock for MyService in a unit test for MyController , how do I make MyController use the mock? It's bit difficult — isn't it?

public class MyController {
    private MyService service = new MyService();

    public String welcome() {
        return service.retrieveWelcomeMessage();

Example With a Dependency Injection

With the help of only two annotations, we can get the instance of MyService easily, which is not tightly coupled. The Spring Framework does all the hard work to make things simpler.

  •  @Component is simply used in the Spring Framework as a bean that you need to manage within your own BeanFactory (an implementation of the Factory pattern).
  • @Autowired is simply used to in the Spring Framework to find the correct match for this specific type and autowire it.

So, Spring framework will create a bean for MyService and autowire it into MyController.

In a unit test, I can ask the Spring Framework to auto-wire the mock of MyService into MyController .

public class MyService {
    public String retrieveWelcomeMessage(){
       return "Welcome to InnovationM";
public class MyController {

    private MyService service;

    public String welcome() {
        return service.retrieveWelcomeMessage();

The Spring Framework has many other features, which are divided into twenty modules to solve many common problems. Here are some of the more popular modules:

  • Spring JDBC
  • Spring MVC
  • Spring AOP
  • Spring ORM
  • Spring JMS
  • Spring Test
  • Spring Expression Language (SpEL)

Aspect Oriented Programming(AOP) is another strong side of the Spring Framework. The key unit in object-oriented programming is the class, whereas, in AOP, the key unit is the aspect. For example, if you want to add the security in your project, logging, etc., you can just use the AOP and keep these as a cross-cutting concern away from your main business logic. You can perform any action after a method call, before a method call, after a method returns, or after the exception arises.

The Spring Framework does not have its own ORM, but it provides a very good integration with ORM, like Hibernate, Apache iBATIS, etc.

In short, we can say that the Spring Framework provides a decoupled way of developing web applications. Web application development becomes easy with the help of these concepts in Spring, like Dispatcher Servlet, ModelAndView, and View Resolver.

If Spring Can Solve so Many Problems, Why Do We Need Spring Boot?

Now, if you have already worked on Spring, think about the problem that you faced while developing a full-fledged Spring application with all functionalities. Not able to come up with one? Let me tell you — there was lot of difficulty to setup Hibernate Datasource, Entity Manager, Session Factory, and Transaction Management. It takes a lot of time for a developer to set up a basic project using Spring MVC with minimum functionality.

        <property name="prefix">
        <property name="suffix">
  <mvc:resources mapping="/webjars/**" location="/webjars/"/>

When we use Hibernate, we have to configure these things like a datasource, EntityManager, etc.

<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
        <property name="driverClass" value="${db.driver}" />
        <property name="jdbcUrl" value="${db.url}" />
        <property name="user" value="${db.username}" />
        <property name="password" value="${db.password}" />
    <jdbc:initialize-database data-source="dataSource">
        <jdbc:script location="classpath:config/schema.sql" />
        <jdbc:script location="classpath:config/data.sql" />
        <property name="persistenceUnitName" value="hsql_pu" />
        <property name="dataSource" ref="dataSource" />
    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory" />
        <property name="dataSource" ref="dataSource" />
    <tx:annotation-driven transaction-manager="transactionManager"/>


How Does Spring Boot Solve This Problem?

  1. Spring Boot does all of those using AutoConfiguration and will take care of all the internal dependencies that your application needs — all you need to do is run your application. Spring Boot will auto-configure with the Dispatcher Servlet, if Spring jar  is in the class path. It will auto-configue to the datasource, if Hibernate jar  is in the class path. Spring Boot gives us a pre-configured set of Starter Projects to be added as a dependency in our project.
  2. During web-application development, we would need the jars that we want to use, which versions of the jars to use, and how to connect them together. All web applications have similar needs, for example, Spring MVC, Jackson Databind, Hibernate core, and Log4j (for logging). So, we had to choose the compatible versions of all these jars. In order to decrease the complexity, Spring Boot has introduced what we call Spring Boot Starters.

Dependency for Spring Web Project



Starters are a set of convenient dependencies that you can include in your Spring Boot application.  For using Spring and Hibernate, we just have to include the spring-boot-starter-data-jpa dependency in the project.

Dependency for Spring Boot Starter Web


The following screenshot shows the different packages under a single dependency that are added into our application:

There are other packages that you will see. Once you add that starter dependency, the Spring Boot Starter Web comes pre-packaged with all of these. As a developer, we would not need to worry about these dependencies and their compatible versions.

Spring Boot Starter Project Options

These are few starter projects to help us get started quickly with developing specific types of applications.

  • spring-boot-starter-web-services: SOAP Web Services
  • spring-boot-starter-web: Web and RESTful applications
  • spring-boot-starter-test: Unit testing and Integration Testing
  • spring-boot-starter-jdbc: Traditional JDBC
  • spring-boot-starter-hateoas: Add HATEOAS features to your services
  • spring-boot-starter-security: Authentication and Authorization using Spring Security
  • spring-boot-starter-data-jpa: Spring Data JPA with Hibernate
  • spring-boot-starter-cache: Enabling Spring Framework’s caching support
  • spring-boot-starter-data-rest: Expose Simple REST Services using Spring Data REST
java ,spring ,spring boot ,web application

Published at DZone with permission of Ankit Kumar . See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}