Differences Between Spring and Spring Boot: Overview, Configuration, and Deployment

This article explains the distinctions between Spring and Spring Boot, covering their core concepts, Maven dependencies, MVC and template engine configurations, security setup, bootstrapping mechanisms, packaging options, and deployment strategies, with detailed code examples throughout.

Selected Java Interview Questions
Selected Java Interview Questions
Selected Java Interview Questions
Differences Between Spring and Spring Boot: Overview, Configuration, and Deployment

Overview

Spring is a comprehensive Java framework providing infrastructure support such as dependency injection, JDBC, MVC, Security, AOP, ORM, and testing modules, while Spring Boot is an extension that eliminates XML configuration and streamlines application setup with auto‑configuration and starter dependencies.

What is Spring

Spring offers a rich set of modules (e.g., Spring JDBC, Spring MVC, Spring Security, Spring AOP, Spring ORM, Spring Test) that reduce boilerplate code and accelerate Java web development.

What is Spring Boot

Spring Boot builds on Spring, removing the need for extensive XML configuration and providing features such as embedded servlet containers (Tomcat, Jetty, Undertow), starter POMs, auto‑configuration, production‑ready metrics, and zero XML requirements.

Configuration Analysis

Maven Dependencies

Typical Spring web dependencies require multiple <dependency> entries for spring-web and spring-webmvc with explicit versions.

<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-web</artifactId>
  <version>5.1.0.RELEASE</version>
</dependency>
... (additional dependencies)

Spring Boot simplifies this to a single starter:

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

MVC Configuration

In Spring, you must define a WebApplicationInitializer and a view resolver bean manually. Spring Boot auto‑configures these via the spring-boot-starter-web and the embedded container.

public class MyWebAppInitializer implements WebApplicationInitializer {
    @Override
    public void onStartup(ServletContext container) {
        AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
        context.setConfigLocation("com.example");
        container.addListener(new ContextLoaderListener(context));
        ServletRegistration.Dynamic dispatcher = container.addServlet("dispatcher", new DispatcherServlet(context));
        dispatcher.setLoadOnStartup(1);
        dispatcher.addMapping("/");
    }
}

Template Engine Configuration

Spring requires explicit Thymeleaf resolver beans, while Spring Boot only needs the spring-boot-starter-thymeleaf starter and optional layout dialect for newer versions.

@Configuration
@EnableWebMvc
public class MvcWebConfig implements WebMvcConfigurer {
    @Bean
    public SpringResourceTemplateResolver templateResolver() {
        SpringResourceTemplateResolver resolver = new SpringResourceTemplateResolver();
        resolver.setApplicationContext(applicationContext);
        resolver.setPrefix("/WEB-INF/views/");
        resolver.setSuffix(".html");
        return resolver;
    }
    @Bean
    public SpringTemplateEngine templateEngine() {
        SpringTemplateEngine engine = new SpringTemplateEngine();
        engine.setTemplateResolver(templateResolver());
        engine.setEnableSpringELCompiler(true);
        return engine;
    }
    @Override
    public void configureViewResolvers(ViewResolverRegistry registry) {
        ThymeleafViewResolver resolver = new ThymeleafViewResolver();
        resolver.setTemplateEngine(templateEngine());
        registry.viewResolver(resolver);
    }
}

Spring Security Configuration

Both Spring and Spring Boot use the same security modules; Spring Boot adds them automatically via the spring-boot-starter-security starter.

@Configuration
@EnableWebSecurity
public class CustomWebSecurityConfigurerAdapter extends WebSecurityConfigurerAdapter {
    @Autowired
    private AuthenticationManagerBuilder auth;
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests().anyRequest().authenticated().and().httpBasic();
    }
    @Bean
    public PasswordEncoder passwordEncoder() {
        return new BCryptPasswordEncoder();
    }
}

Spring Boot Bootstrapping

The entry point is a class annotated with @SpringBootApplication containing a main method that calls SpringApplication.run. Embedded containers are started automatically, and the application can also be packaged as a WAR by extending SpringBootServletInitializer.

@SpringBootApplication
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

public class ServletInitializer extends SpringBootServletInitializer {
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return builder.sources(Application.class);
    }
}

Packaging and Deployment

Both frameworks support Maven and Gradle. Spring Boot adds the ability to create executable JARs or WARs with embedded containers, simplifying deployment and offering features like externalized configuration, random port selection for tests, and flexible dependency management.

Conclusion

Spring Boot is essentially an extension of Spring that streamlines development, testing, and deployment by providing auto‑configuration, starter dependencies, and embedded servers, making it a more convenient choice for modern Java web applications.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

javaConfigurationspringmavenSpring BootsecurityWeb Development
Selected Java Interview Questions
Written by

Selected Java Interview Questions

A professional Java tech channel sharing common knowledge to help developers fill gaps. Follow us!

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.