Lecture 33: Spring Boot Configuration & Setup

BMC201 - Web Technology

Dr. Prashant Kumar Nag

2026-04-21

Lecture 33

Spring Boot Configuration & Setup

Week 9 | Unit V: Spring Boot & REST Services
BMC201 - Web Technology
Dr. Prashant Kumar Nag, Assistant Professor

Learning Objectives


  • Explain what Spring Boot is and how it simplifies Spring development
  • Create a Spring Boot project structure
  • Configure application using application.properties and application.yml
  • Understand auto-configuration and customization
  • Use Spring Boot starters effectively
  • Configure embedded server properties

Prerequisites


Before this lecture, quickly revise:

  • Core Spring Framework concepts (IoC, DI) from previous lectures
  • Maven/Gradle basics for dependency management
  • Java annotations and configuration approaches

Syllabus Mapping


  • Unit V topic focus: Spring Boot Configuration & Setup
  • CO alignment: implementation understanding + configuration reasoning
  • Assessment alignment: short definitions + long implementation/design questions

Agenda


  • 5-minute recap from previous lecture
  • Concept deep dive: Spring Boot Configuration & Setup
  • Code/configuration walkthrough and output analysis
  • Debug checklist and exam-oriented summary

Introduction


Spring Boot simplifies Spring application development by eliminating boilerplate configuration and providing production-ready defaults.

Think About It


How much XML configuration does a typical Spring MVC application need? Can this be simplified?

What is Spring Boot?


Spring Boot is an opinionated framework built on top of Spring Framework that simplifies configuration and deployment.

Key features: - Auto-configuration based on classpath - Embedded server (Tomcat, Jetty, Undertow) - Production-ready features (health checks, metrics) - No XML configuration required

Spring Boot = Spring Framework + Embedded Server + Auto-configuration + Starter Dependencies

Spring Framework vs Spring Boot


Aspect Spring Framework Spring Boot
Configuration Manual XML/Java config Auto-configuration
Server External (Tomcat/JBoss) Embedded server
Dependency Management Manual versions Starter POMs
Production Features Manual setup Built-in actuator
Setup Time Hours Minutes

Spring Boot does NOT replace Spring — it makes Spring easier to use.

Spring Boot Project Structure


my-spring-boot-app/
├── src/
│   ├── main/
│   │   ├── java/
│   │   │   └── com/example/demo/
1│   │   │       ├── DemoApplication.java      //
│   │   │       ├── controller/
│   │   │       ├── service/
│   │   │       └── repository/
│   │   └── resources/
2│   │       ├── application.properties        //
3│   │       ├── static/                       //
4│   │       └── templates/                    //
│   └── test/
5├── pom.xml                                   //
└── target/
1
Main application class with @SpringBootApplication
2
Configuration file
3
Static resources (CSS, JS, images)
4
Template files (Thymeleaf, Freemarker)
5
Maven dependency file

@SpringBootApplication Annotation


@SpringBootApplication                        // #<1>
public class DemoApplication {
  public static void main(String[] args) {
    SpringApplication.run(DemoApplication.class, args); // #<2>
  }
}
  1. Composite annotation = @Configuration + @EnableAutoConfiguration + @ComponentScan
  2. Bootstraps the application with auto-configuration

Breakdown: - @Configuration: Allows bean definitions - @EnableAutoConfiguration: Automatically configures beans based on classpath - @ComponentScan: Scans for components in current package and sub-packages

Configuration with application.properties


# Server Configuration
1server.port=8081                              //

# Application Name
2spring.application.name=my-app                //

# Database Configuration
3spring.datasource.url=jdbc:mysql://localhost:3306/mydb //
spring.datasource.username=root
spring.datasource.password=root123

# Logging Level
4logging.level.root=INFO                       //
logging.level.com.example=DEBUG
1
Change default port from 8080
2
Set application name
3
Configure database connection
4
Set logging levels

Configuration with application.yml


server:
1  port: 8081                                  //

spring:
  application:
    name: my-app
2  datasource:                                 //
    url: jdbc:mysql://localhost:3306/mydb
    username: root
    password: root123

3logging:                                      //
  level:
    root: INFO
    com.example: DEBUG
1
YAML format is more readable
2
Hierarchical structure with indentation
3
Easier to organize related properties

Both formats work — choose based on team preference. YAML is more popular for complex configurations.

Auto-Configuration Explained


Spring Boot automatically configures beans based on: - JARs in classpath - Properties defined in configuration files - Existing bean definitions

Example: If H2 database is in classpath and no DataSource bean exists: → Spring Boot auto-configures an in-memory H2 database

View auto-configuration report:

java -jar myapp.jar --debug

Disabling Specific Auto-Configuration


@SpringBootApplication(
  exclude = {DataSourceAutoConfiguration.class} // #<1>
)
public class DemoApplication {
  public static void main(String[] args) {
    SpringApplication.run(DemoApplication.class, args);
  }
}
  1. Explicitly exclude auto-configuration classes

In application.properties:

spring.autoconfigure.exclude=\
  org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration

Spring Boot Starter Dependencies


Starters are convenient dependency descriptors that bundle related dependencies.

Starter Purpose Key Dependencies
spring-boot-starter-web Web applications Spring MVC, Tomcat, JSON
spring-boot-starter-data-jpa JPA database access Hibernate, JDBC
spring-boot-starter-security Security Spring Security
spring-boot-starter-test Testing JUnit, Mockito, AssertJ
spring-boot-starter-thymeleaf Template engine Thymeleaf

Maven example:

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

Embedded Server Configuration


Spring Boot includes embedded servers — no separate installation needed.

Change embedded server:

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-web</artifactId>
  <exclusions>
    <exclusion>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-tomcat</artifactId>
    </exclusion>
  </exclusions>
</dependency>
<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-jetty</artifactId>
</dependency>

Server properties:

server.port=9090
server.servlet.context-path=/api
server.compression.enabled=true

@ConfigurationProperties for Custom Config


@Configuration
@ConfigurationProperties(prefix = "app")      // #<1>
public class AppConfig {
  private String name;                        // #<2>
  private String version;
  private int timeout;

  // getters and setters
}

// In application.properties:
app.name=MyApp                                // #<3>
app.version=1.0.0
app.timeout=5000
  1. Binds properties with prefix “app” to this class
  2. Properties map to fields automatically
  3. Type-safe configuration binding

Environment-Specific Configuration with Profiles


Create profile-specific files: - application-dev.properties — development - application-test.properties — testing - application-prod.properties — production

Activate profile:

# In application.properties
spring.profiles.active=dev

Or via command line:

java -jar myapp.jar --spring.profiles.active=prod

In code:

@Profile("dev")
@Configuration
public class DevConfig { ... }

Memory Booster


Syllabus memory points for Spring Boot Configuration & Setup:

  • Core recall: Auto-configuration, starters, embedded server, application.properties
  • Exam compare: Spring vs Spring Boot setup complexity
  • Practical anchor: Create Spring Boot project and configure server port

Live Demo


Live implementation for Spring Boot Configuration & Setup:

📋 Open Demo: Lecture 33 - Spring Boot Configuration & Setup

Demo checklist: - create a Spring Boot project with Spring Initializr - configure application.properties for custom port - add a starter dependency and verify auto-configuration

Resources & References


Structured Debug Checklist


  1. verify @SpringBootApplication is on main class and package structure is correct
  2. check application.properties/yml syntax and property names
  3. inspect startup logs for auto-configuration report (use –debug flag)
  4. validate starter dependencies in pom.xml/build.gradle are compatible
  5. ensure no port conflicts if server fails to start

Exam Preparation Questions: Short


  • Define Spring Boot and explain its purpose.
  • What is auto-configuration? How does Spring Boot determine which beans to configure?
  • Differentiate: Spring Framework vs Spring Boot.
  • List four commonly used Spring Boot starters and their purposes.
  • Explain the @SpringBootApplication annotation.

Exam Preparation Questions: Long


  • Explain Spring Boot Configuration & Setup with project structure and configuration examples.
  • Compare application.properties and application.yml with examples.
  • Discuss how Spring Boot auto-configuration works internally.
  • Explain profile-based configuration for different environments (dev, test, prod).

Practice Task


  • Implement: Create a Spring Boot web application with custom configuration.
  • Configure server port, application name, and logging level in application.properties.
  • Add a simple REST controller and test the application.
  • Document one configuration mistake you encountered and the exact fix.

Checklist


Can you:

  • explain Spring Boot Configuration & Setup in your own words?
  • create a Spring Boot project from scratch?
  • configure application.properties for common scenarios?
  • identify and fix configuration-related startup issues?

Next Lecture


  • Topic: Lecture 34 - Spring Boot Annotations & Build Systems
  • Preparation required: revise this lecture summary and practice creating a Spring Boot project

Spring Boot Configuration & Setup

Next: Lecture 34 - Spring Boot Annotations & Build Systems