Lecture 38: Spring Boot Configuration, Annotations & Build Systems

BMC201 - Web Technology

Mr. Prashant Kumar Nag

2026-03-26

Lecture 38

Spring Boot Configuration, Annotations & Build Systems

Week 12 | Unit V: Spring Boot
BMC201 - Web Technology
Mr. Prashant Kumar Nag, Assistant Professor

Learning Objectives


  • Explain why Spring Boot is preferred over classic Spring setup
  • Configure app settings using application.properties and profiles
  • Use core Spring Boot annotations correctly
  • Compare Maven and Gradle build systems
  • Structure a Boot project using clean package conventions
  • Use actuator basics for environment and health visibility

Why Spring Boot?


  • Auto-configuration reduces boilerplate
  • Embedded server (Tomcat/Jetty/Undertow)
  • Starter dependencies simplify build files
  • Production-ready defaults with actuator support
  • Quick setup for REST and microservices

Recommended Project Structure


src/main/java/com/example/app/
  Application.java
  controller/
  service/
  repository/
  entity/
src/main/resources/
  application.properties
  application-dev.properties
  application-prod.properties
pom.xml or build.gradle

Keep Application.java at top package so component scan covers subpackages.

Core Spring Boot Annotations


Annotation Purpose
@SpringBootApplication Enables auto-config + component scan + config
@Configuration Bean definition class
@Bean Registers method return as bean
@ConfigurationProperties Binds external config to POJO
@Value Injects individual property values

application.properties Example


server.port=8081
spring.application.name=task-service
spring.datasource.url=jdbc:mysql://localhost:3306/taskdb
spring.datasource.username=root
spring.datasource.password=secret
spring.jpa.hibernate.ddl-auto=update
logging.level.com.example=DEBUG
management.endpoints.web.exposure.include=health,info,metrics

Environment Profiles


# application-dev.properties
logging.level.root=DEBUG
spring.jpa.show-sql=true

# application-prod.properties
logging.level.root=INFO
spring.jpa.show-sql=false
# Run with dev profile
java -jar app.jar --spring.profiles.active=dev

@ConfigurationProperties Demo


@ConfigurationProperties(prefix = "app.mail")
@Component
public class MailProps {
  private String host;
  private int port;
  private String sender;
}
app.mail.host=smtp.example.com
app.mail.port=587
app.mail.sender=noreply@example.com

Build Systems: Maven vs Gradle


Feature Maven Gradle
Format XML (pom.xml) Groovy/Kotlin DSL
Learning Curve Easier initially Higher initially
Performance Good Better with incremental builds
Convention Strong conventions More flexible customization

Starter Dependency Example


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

Starter artifacts include compatible transitive dependencies automatically.

Actuator Essentials


management.endpoints.web.exposure.include=health,info,metrics
management.endpoint.health.show-details=always
/actuator/health
/actuator/info
/actuator/metrics

Common Mistakes to Avoid


  • Keeping secrets hard-coded in application.properties
  • Using same profile settings for local and production
  • Placing Application.java in wrong package (scan misses beans)
  • Managing dependency versions manually for Spring starters
  • Exposing all actuator endpoints in production without security

Summary


  • Spring Boot accelerates development with opinionated defaults
  • Profiles keep configuration environment-specific and clean
  • Build tools and starter dependencies reduce setup friction
  • Proper structure and configuration are key for scalable apps

Questions?

Next: Lecture 39 - RESTful Web Services: Controllers, Request Mapping, CRUD APIs