DEV Community

Cover image for Spring Vs Spring Boot:  Brief Overview and Comparison
eduwyre
eduwyre

Posted on

Spring Vs Spring Boot: Brief Overview and Comparison

Spring is a the core java framework used heavily in web and JEE applications development in general. Before we continue, it is worth noting that Spring is the core framework whereas spring boot is the extension module built on top of Spring core. So, while both bring in many things in common, you will find subtle differences between the two.

Spring vs Spring Boot: Brief Introduction

At a very basic level, Spring is a low-level framework where you need to do a lot of manual work, but Spring Boot brings in many predefined ways to automate programming tasks.

Having said that, also understand that Spring can do a lot more, but Spring Boot is targeted specifically towards web development and microservices

What is Spring?

Spring provides overall infrastructural backing to develop java enterprise applications. Two powerful features of spring include dependency injection (DI) and inversion of Control. It also provides a very solid configurational mechanism to speed develop Java EE applications.

Over the last few years, Spring has turned into a very wide ecosystem of modules and that are used in various areas of application development.

Some of the popular modules in the ecosystem include Spring ORM, Spring MVC Test, Spring Cloud, Spring Batch, Spring Security, and a lot more.

When working on an enterprise Java application, you can pick and choose one or more of Spring modules and get your application up and running.

Some of the key tasks you can achieve with spring are as below –

  • Build Serverless cloud applications
  • Create batches to automate repetitive tasks
  • Build non-blocking asynchronous applications
  • Server-side development with battletested security
  • Event driven architecture implementation
  • Scalable microservices development
  • And a lot more.

Spring continuously keeps on adding more projects in the overall ecosystem. Some of the recent additions include Spring Shell that provides readymade jars to put together a fully functional CLI application. Another example includes Spring Flow which is based on JavaScript and allows use of HTML5 visual builder for simple pipelines and graphs.

Spring framework is used heavily in streaming applications like Streaming TV, Streaming Audio, shopping apps and a lot more. Many top organizations like Google, Microsoft and Alibaba are regular contributors and supports for the advancement of spring framework.

For absolute beginners, know that You can learn Spring as well as Spring Boot framework by following common set of Spring tutorials and Courses as most tutorials provide intro to Spring and then carry on to explain Spring Boot.

What is Spring Boot?

Like I stated above, Spring Boot is high level framework built on top of spring and requires minimal configuration to build web applications. One of the key drawbacks of core Spring is the need for lot of manual configuration and that is what resulted in creation of Spring Boot.

Based on the choices you make for your web application development, spring boot generates the configuration for you automatically, it saves a lot of time.

Key features of Spring Boot are as below –

  • Create fully functional independent spring applications
  • Auto includes war files for Tomcat, Jetty and even Undertow. You just decide what you want, spring Boot takes care of the WAR files and deployment
  • Brings pre-defined configurations for started web application.
  • Auto configuration of modules from Spring ecosystem as well as many third-party libraries
  • Out of the box metrics, health checks and other reports.
  • No manual XML configuration required.

Spring Boot does take away some flexibility with opinionated configuration that it offers, but that is what saves all the time. If you are not in for that, you can go for core/raw Spring and do it all by yourself.

Dependency Management: Spring vs Spring Boot

Let us look at very basic example of how developers can manage dependencies in both Spring and Spring Boot Frameworks -

Minimum dependency required in Spring, for a web application:

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-web</artifactId>
    <version>5.3.5</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc</artifactId>
    <version>5.3.5</version>
</dependency>
Enter fullscreen mode Exit fullscreen mode

Minimum dependency required in Spring Boot for web application:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <version>2.4.4</version>
</dependency>
Enter fullscreen mode Exit fullscreen mode

Notice above the difference in number of lines, and the difference becomes exponential when application complexity increases along with the dependencies. Spring Boot makes it simple with the help of many starter packs. Some of the most popular are as listed below -

  • spring-boot-starter-thymeleaf - Includes the template engine
  • spring-boot-starter-web - Creates web app with embedded container
  • spring-boot-starter-aop - AOP included for aspect oriented programming in Spring Boot applications
  • spring-boot-starter-artemis - JMS messaging with Apache Artemis
  • spring-boot-starter-web-services - Web Services starter pack
  • spring-boot-starter-mail - Email sending features in JEE application
  • spring-boot-starter-data-jpa - Including data JPA with Hibernate

If you are not using Spring Boot then every single dependency from above list in core Spring will make you write many lines of configuration.

Spring vs Spring Boot: Dependency configuration for Security

Check below example to configure Security in Spring application, without Spring Boot -

@Configuration
@EnableWebSecurity
public class CustomWebSecurityConfigurerAdapter extends WebSecurityConfigurerAdapter {

    @Autowired
    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
        auth.inMemoryAuthentication()
          .withUser("user1")
            .password(passwordEncoder()
            .encode("user1Pass"))
          .authorities("ROLE_USER");
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests()
          .anyRequest().authenticated()
          .and()
          .httpBasic();
    }

    @Bean
    public PasswordEncoder passwordEncoder() {
        return new BCryptPasswordEncoder();
    }
}
Enter fullscreen mode Exit fullscreen mode

With Spring Boot, you only need to include the security starter pack - spring-boot-starter-security.

There is even a spring initializer that helps you make application choices on the user interface and generates the application dependencies automatically.
Check out below image –
Alt Text

Conclusion

Spring was launched to do a lot of things in Java, but developers didn’t like it too much due to the manual configuration overheads. However, spring Boot brought back the developers’ interest soon after and helped grow spring ecosystem to the heights it enjoys now.

This brings us to the end of this Spring vs Spring Boot comparison. Do let us know your views working with these frameworks, via comments.

Top comments (1)

Collapse
 
nyangweso profile image
Rodgers Nyangweso

awesome, good work in putting this together