Cheps
Cheps

Reputation: 515

What is the difference between Spring and Spring Boot?

There are many people who advised me to use Spring Boot instead of Spring to develop REST web services.

What is the exact difference between Spring and Spring Boot?

Upvotes: 37

Views: 29729

Answers (6)

Beezer
Beezer

Reputation: 1108

Unfortunately and I mean this out of personal frustration with Spring boot, I have yet to see any real quantified list, where the differences are explicitly outlined. There is only qualifications such as the rubbish sentence "...opinionated view..." which are bandied about.

What is clear, is that SpringBoot has wrapped up groups of Spring annotations into its own set of annotations, implicitly. Further obfuscating, and making the need for anyone starting out in SpringBoot to have to commit to memory what a particular SpringBoot annotation represents.

My reply therefore is of no quantifiable benefit to the original question, which is analogous to that of the SpringBoot authors. Those behind Spring IMO deliberately set-out to obfuscate, which reflects the obtuseness of their JavaDoc and API's (see SpringBatch API's as an example, if you think I am flaming) that makes one wonder the value of their open-source ethos.

My quest for figuring out SpringBoot continues.

Update. 22-08-2022

Read this (https://docs.spring.io/spring-boot/docs/current/reference/html/using.html#using.auto-configuration) and you will figure out for yourself what "opinionated" means. There are over 140 Config classes that Springboot can use for this opinionated view, depending on what is on your classpath. yes, on your classpath. Finally and bizzarely, the annotation @SpringBootApplication is a configuration annotation as it includes it. Go figure :=)

Upvotes: 10

Premraj
Premraj

Reputation: 74671

  • Spring eliminate boilerplate code.
  • Spring-boot eliminates boilerplate configurations.
    more

Upvotes: 1

Minar Mahmud
Minar Mahmud

Reputation: 2665

  • For Spring Framework, you need to configure your project using XML configuration or Java configuration.

    But for Spring Boot, these are preconfigured according to Spring team's view for rapid development. That is why Spring Boot is said to be an "opinionated view" of Spring Framework. It follows Convention over Configuration design paradigm.

    Note: These configurations include view resolvers for MVC, transaction managers, way of locating container managed beans (Spring beans) and many more. And of course you can override any of these preconfigurations according to your need.

  • Spring Boot supports embedded servlet containers like Tomcat, Jetty or Undertow to create standalone applications, which Spring Framework doesn't.

Upvotes: 1

bpjoshi
bpjoshi

Reputation: 1141

Spring Boot is opinionated view of Spring Framework projects.Let's analyse it through one program taken from Spring Boot Documentation.

@RestController
@EnableAutoConfiguration
public class Example {

    @RequestMapping("/")
    String home() {
        return "Hello World!";
    }

    public static void main(String[] args) throws Exception {
        SpringApplication.run(Example.class, args);
    }
  }

It's a very basic REST API and you need to add Spring-boot-starter-web in your POM.xml for the same. Since you have added starter-web dependency, the annotation @EnableAutoConfiguration guesses that you want to develop a web application and sets up Spring accordingly.

Spring Boot auto-configuration attempts to automatically configure your Spring application based on the jar dependencies that you have added. For example, if HSQLDB is on your classpath, and you have not manually configured any database connection beans, then Spring Boot auto-configures an in-memory database.

It's opinionated like maven. Maven creates a project structure for you which it thinks is the general pattern of projects like it adds src/main/java folder or resource folder for you.

Spring boot helps in faster development. It has many starter projects that helps you get going quite faster. It also includes many non functional features like: embedded servers, security, metrics, health checks etc. In short, it makes, spring based application development easier with minimally invading code(Less configuration files, less no of annotations).

Reference: https://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#boot-documentation-about

Upvotes: 3

medvedev1088
medvedev1088

Reputation: 3755

In short

  1. Spring Boot reduces the need to write a lot of configuration and boilerplate code.
  2. It has an opinionated view on Spring Platform and third-party libraries so you can get started with minimum effort.
  3. Easy to create standalone applications with embedded Tomcat/Jetty/Undertow.
  4. Provides metrics, health checks, and externalized configuration.

You can read more here http://projects.spring.io/spring-boot/

Upvotes: 26

digitaljoel
digitaljoel

Reputation: 26584

Basically, Spring Boot is an opinionated instance of a Spring application.

Spring Boot is a rapid application development platform. It uses various components of Spring, but has additional niceties like the ability to package your application as a runnable jar, which includes an embedded tomcat (or jetty) server. Additionally, Spring Boot contains a LOT of auto-configuration for you (the opinionated part), where it will pick and choose what to create based on what classes/beans are available or missing.

I would echo their sentiment that if you are going to use Spring I can't think of any reasons to do it without Spring Boot.

Upvotes: 9

Related Questions