This comprehensive Spring Boot 3 course teaches you how to build enterprise-level Java applications using Spring Boot and Hibernate. The course covers everything from basic setup to advanced features like REST APIs, database integration, and security.
- Develop Spring Boot applications from scratch
- Leverage Hibernate/JPA for database access
- Build REST APIs using Spring Boot
- Create Spring MVC applications
- Connect Spring Boot apps to databases for CRUD operations
- Apply Spring Security to control application access
- Use all Java configuration (no XML) with Maven
- Java programming experience (OOP, classes, interfaces, inheritance, exception handling, collections)
- Java Development Kit (JDK): Version 17 or higher (required for Spring Boot 3)
- IDE: Any Java IDE works
- IntelliJ IDEA Community Edition (free) - recommended
- Eclipse, NetBeans, or any other Java IDE
- Download IntelliJ: https://www.jetbrains.com/idea/download
Before starting the course, ensure you can:
- Run a basic "Hello World" Java application in your IDE
- Verify JDK 17+ is installed and configured
Traditional Spring applications are difficult to set up:
- Complex JAR dependency management
- Tedious XML or Java configuration
- Manual server installation (Tomcat, JBoss, etc.)
- Minimize manual configuration: Auto-configuration based on properties and classpath
- Resolve dependency conflicts: Simplified Maven/Gradle dependency management
- Embedded HTTP server: No need for separate server installation (Tomcat, Jetty, Undertow)
- Easier to get started: Focus on business logic, not boilerplate
- Spring Boot uses Spring Framework behind the scenes
- It doesn't replace Spring MVC, Spring REST, etc. - it makes them easier to use
- No performance difference from regular Spring applications
- Works with any IDE (no special IDE required)
Create Spring Boot projects quickly using: http://start.spring.io
Features:
- Select dependencies visually
- Generate Maven or Gradle projects
- Download and import into any IDE
- Configure project at Spring Initializr website
- Download the ZIP file
- Unzip the file
- Import into your IDE
File: src/main/java/com/example/HelloWorldApp.java
package com.example;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication // Enables auto-configuration + component scanning
@RestController
public class HelloWorldApp {
public static void main(String[] args) {
SpringApplication.run(HelloWorldApp.class, args);
}
@GetMapping("/")
public String hello() {
return "Hello, Spring Boot!";
}
@GetMapping("/api/welcome")
public String welcome() {
return "Welcome to Spring Boot 3!";
}
}File: src/main/resources/application.properties
# Server Configuration
server.port=8080
server.servlet.context-path=/
# Application Name
spring.application.name=HelloWorldApp
# Logging
logging.level.root=INFO
logging.level.com.example=DEBUG# Option 1: From IDE
# Right-click on HelloWorldApp.java → Run
# Option 2: Maven command
./mvnw spring-boot:run
# Option 3: Package and run JAR
./mvnw package
java -jar target/hello-world-app.jar# Test endpoint 1
curl http://localhost:8080/
# Test endpoint 2
curl http://localhost:8080/api/welcome
# View actuator endpoints
curl http://localhost:8080/actuator/healthExpected Output:
Hello, Spring Boot!
Welcome to Spring Boot 3!
{"status":"UP"}
spring-boot-project/
├── pom.xml # Parent POM
├── src/
│ ├── main/
│ │ ├── java/com/example/
│ │ │ ├── SpringBootApp.java # Main class
│ │ │ ├── controller/
│ │ │ │ └── UserController.java
│ │ │ ├── service/
│ │ │ │ └── UserService.java
│ │ │ ├── repository/
│ │ │ │ └── UserRepository.java
│ │ │ └── model/
│ │ │ └── User.java
│ │ └── resources/
│ │ ├── application.properties
│ │ └── application-prod.properties
│ └── test/java/com/example/
│ └── UserControllerTest.java
File: src/main/java/com/example/SpringBootApp.java
@SpringBootApplication
public class SpringBootApp {
public static void main(String[] args) {
SpringApplication.run(SpringBootApp.class, args);
System.out.println("✓ Application started successfully!");
}
}File: src/main/java/com/example/model/User.java
package com.example.model;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Entity
@Table(name = "users")
@Data
@NoArgsConstructor
@AllArgsConstructor
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@Column(nullable = false)
private String firstName;
@Column(nullable = false)
private String lastName;
@Column(unique = true, nullable = false)
private String email;
private String phoneNumber;
}File: src/main/java/com/example/repository/UserRepository.java
package com.example.repository;
import com.example.model.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import java.util.Optional;
import java.util.List;
@Repository
public interface UserRepository extends JpaRepository<User, Integer> {
Optional<User> findByEmail(String email);
List<User> findByFirstName(String firstName);
List<User> findByFirstNameAndLastName(String firstName, String lastName);
}File: src/main/java/com/example/service/UserService.java
package com.example.service;
import com.example.model.User;
import com.example.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Optional;
@Service
public class UserService {
@Autowired
private UserRepository userRepository;
public List<User> getAllUsers() {
return userRepository.findAll();
}
public Optional<User> getUserById(Integer id) {
return userRepository.findById(id);
}
public User createUser(User user) {
return userRepository.save(user);
}
public User updateUser(Integer id, User userDetails) {
return userRepository.findById(id)
.map(user -> {
user.setFirstName(userDetails.getFirstName());
user.setLastName(userDetails.getLastName());
user.setEmail(userDetails.getEmail());
user.setPhoneNumber(userDetails.getPhoneNumber());
return userRepository.save(user);
})
.orElseThrow(() -> new RuntimeException("User not found"));
}
public void deleteUser(Integer id) {
userRepository.deleteById(id);
}
}File: src/main/java/com/example/controller/UserController.java
package com.example.controller;
import com.example.model.User;
import com.example.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("/api/users")
public class UserController {
@Autowired
private UserService userService;
// GET all users
@GetMapping
public ResponseEntity<List<User>> getAllUsers() {
List<User> users = userService.getAllUsers();
return ResponseEntity.ok(users);
}
// GET user by ID
@GetMapping("/{id}")
public ResponseEntity<User> getUserById(@PathVariable Integer id) {
return userService.getUserById(id)
.map(ResponseEntity::ok)
.orElse(ResponseEntity.notFound().build());
}
// POST - Create new user
@PostMapping
public ResponseEntity<User> createUser(@RequestBody User user) {
User createdUser = userService.createUser(user);
return ResponseEntity.status(HttpStatus.CREATED).body(createdUser);
}
// PUT - Update user
@PutMapping("/{id}")
public ResponseEntity<User> updateUser(@PathVariable Integer id,
@RequestBody User userDetails) {
User updatedUser = userService.updateUser(id, userDetails);
return ResponseEntity.ok(updatedUser);
}
// DELETE - Delete user
@DeleteMapping("/{id}")
public ResponseEntity<Void> deleteUser(@PathVariable Integer id) {
userService.deleteUser(id);
return ResponseEntity.noContent().build();
}
}File: src/main/resources/application.properties
# ==================== SERVER ====================
server.port=8080
server.servlet.context-path=/
# ==================== DATABASE ====================
spring.datasource.url=jdbc:mysql://localhost:3306/springboot_db
spring.datasource.username=root
spring.datasource.password=root123
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
# ==================== JPA / HIBERNATE ====================
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect
# ==================== LOGGING ====================
logging.level.root=INFO
logging.level.com.example=DEBUG
logging.level.org.springframework.web=DEBUG
logging.level.org.hibernate.SQL=DEBUG
logging.file.name=logs/application.log
# ==================== APPLICATION ====================
spring.application.name=User Management API
app.version=1.0.0File: src/test/java/com/example/UserControllerTest.java
package com.example;
import com.example.model.User;
import com.example.service.UserService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MockMvc;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.Optional;
import static org.mockito.Mockito.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
@SpringBootTest
@AutoConfigureMockMvc
public class UserControllerTest {
@Autowired
private MockMvc mockMvc;
@MockBean
private UserService userService;
@Test
public void testGetUserById() throws Exception {
User user = new User(1, "John", "Doe", "john@example.com", "1234567890");
when(userService.getUserById(1)).thenReturn(Optional.of(user));
mockMvc.perform(get("/api/users/1"))
.andExpect(status().isOk())
.andExpect(jsonPath("$.firstName").value("John"))
.andExpect(jsonPath("$.email").value("john@example.com"));
}
@Test
public void testCreateUser() throws Exception {
User user = new User(null, "Jane", "Smith", "jane@example.com", "0987654321");
User savedUser = new User(1, "Jane", "Smith", "jane@example.com", "0987654321");
when(userService.createUser(any(User.class))).thenReturn(savedUser);
mockMvc.perform(post("/api/users")
.contentType(MediaType.APPLICATION_JSON)
.content(new ObjectMapper().writeValueAsString(user)))
.andExpect(status().isCreated())
.andExpect(jsonPath("$.id").value(1));
}
}Maven is a project management and build tool that:
- Manages JAR dependencies automatically
- Downloads required libraries from Maven Central Repository
- Handles transitive dependencies
- Provides standard directory structure
- Simplifies build and run processes
project-root/
├── src/main/java/ # Java source code
├── src/main/resources/ # Properties/config files
├── src/main/webapp/ # JSP, web config, assets (for WAR)
├── src/test/java/ # Unit testing code
├── target/ # Compiled code (auto-created)
└── pom.xml # Project configuration
The Project Object Model file contains:
- Project metadata (name, version, packaging type)
- Dependencies (Spring, Hibernate, etc.)
- Build plugins and custom tasks
Every Maven project is uniquely identified by:
<groupId>com.myapp</groupId> <!-- Organization -->
<artifactId>mycoolapp</artifactId> <!-- Project name -->
<version>1.0.FINAL</version> <!-- Version -->- Option 1: Visit project websites (spring.io, hibernate.org)
- Option 2: Search at https://central.sonatype.com (recommended)
Curated collections of Maven dependencies grouped together and tested by Spring team.
- No need to list individual dependencies
- Compatible versions guaranteed
- Reduces Maven configuration significantly
| Starter | Description |
|---|---|
spring-boot-starter-web |
Web apps, REST, validation (includes Tomcat) |
spring-boot-starter-security |
Spring Security support |
spring-boot-starter-data-jpa |
Database support with JPA and Hibernate |
spring-boot-starter-test |
Testing frameworks (JUnit, Mockito, etc.) |
Full list: Spring Boot Starters Reference
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>This single dependency includes:
- spring-web
- spring-webmvc
- hibernate-validator
- tomcat
- JSON libraries
- And more...
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.x.x</version>
</parent>Provides:
- Maven defaults (compiler level, UTF-8 encoding)
- Dependency version management
- No need to specify versions for Spring Boot starters
- Default Spring Boot plugin configuration
<properties>
<java.version>17</java.version>
</properties>mvnw.cmd(Windows) /mvnw.sh(Linux/Mac)- Allows running Maven without installing it
- Auto-downloads correct Maven version if needed
# Use Maven wrapper
./mvnw clean compile test
./mvnw spring-boot:run
# Or use installed Maven (if available)
mvn clean compile test
mvn spring-boot:runFile: src/main/resources/application.properties
Configure Spring Boot and custom properties:
# Server configuration
server.port=8585
# Custom properties
coach.name=Mickey Mouse
team.name=The Mouse Crew@RestController
public class FunRestController {
@Value("${coach.name}")
private String coachName;
@Value("${team.name}")
private String teamName;
}- Location:
src/main/resources/static/ - Serves: HTML, CSS, JavaScript, images
⚠️ Warning: Don't usesrc/main/webapp/for JAR packaging (only for WAR)
- Location:
src/main/resources/templates/ - Supported engines: FreeMarker, Thymeleaf, Mustache
- Thymeleaf is popular and covered later in course
Manual application restart required after code changes.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>Features:
- Automatic application restart on code changes
- No additional code required
-
Preferences → Build, Execution, Deployment → Compiler
- ✅ Check "Build project automatically"
-
Preferences → Advanced Settings
- ✅ Check "Allow auto-make to start even if developed application is running"
Production-ready features to monitor and manage your application.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>| Endpoint | Description |
|---|---|
/actuator/health |
Application health status |
/actuator/info |
Application information |
/actuator/beans |
All Spring beans |
/actuator/mappings |
All @RequestMapping paths |
/actuator/metrics |
Application metrics |
# Expose all endpoints
management.endpoints.web.exposure.include=*
# Expose specific endpoints
management.endpoints.web.exposure.include=health,info
# Exclude endpoints
management.endpoints.web.exposure.exclude=beans,mappings
# Enable info endpoint
management.info.env.enabled=true
# Custom info
info.app.name=My Super Cool App
info.app.description=A crazy and fun app!
info.app.version=1.0.0<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>spring.security.user.name=admin
spring.security.user.password=secret123Note: /health remains public by default. All other endpoints require authentication.
Spring Boot apps are self-contained:
- Application code + embedded server (Tomcat) in one JAR
- No separate server installation needed
- Simply run the main application class
- Contains
@SpringBootApplicationannotation
# Package the application
./mvnw package
# Run the JAR
java -jar target/mycoolapp-0.0.1-SNAPSHOT.jar./mvnw spring-boot:runSpring Boot apps can also be packaged as WAR files for deployment to external servers (Tomcat, JBoss, WebSphere).
# Log levels
logging.level.org.springframework=DEBUG
logging.level.org.hibernate=TRACE
logging.level.com.myapp=INFO
# Log file
logging.file.name=my-app.log
logging.file.path=c:/logsLog Levels: TRACE, DEBUG, INFO, WARN, ERROR, FATAL, OFF
# Server port
server.port=7070
# Context path
server.servlet.context-path=/my-app
# Session timeout
server.servlet.session.timeout=15mAccess: http://localhost:7070/my-app/
# Base path
management.endpoints.web.base-path=/actuator
# Expose endpoints
management.endpoints.web.exposure.include=*
management.endpoints.web.exposure.exclude=beansspring.security.user.name=admin
spring.security.user.password=topsecretspring.datasource.url=jdbc:mysql://localhost:3306/mydb
spring.datasource.username=dbuser
spring.datasource.password=dbpass- Spring Boot Properties Reference: Over 1,000+ configuration properties available
- Spring Projects: Spring Cloud, Spring Data, Spring Batch, Spring Security, Spring Web Services, Spring LDAP, and more
- Course Materials: All source code and PDF slides available for download
- Questions: Post in the classroom discussion forum
If you have questions or need assistance:
- Post in the classroom discussion forum
- Review the comprehensive documentation
- Check the official Spring Boot documentation
# 🔨 Maven Wrapper (if Maven not installed)
./mvnw clean compile test # Clean, compile, and test
./mvnw package # Create JAR/WAR file
./mvnw spring-boot:run # Run application directly
# 🔧 Regular Maven (if installed)
mvn clean compile test # Clean, compile, and test
mvn package # Create JAR/WAR file
mvn spring-boot:run # Run application directly
# 🚀 Run packaged application
java -jar target/mycoolapp.jar
# 🐳 Docker Commands (if using Docker)
docker build -t myapp .
docker run -p 8080:8080 myapp
# 🔍 Useful Development Commands
./mvnw dependency:tree # View dependency hierarchy
./mvnw spring-boot:build-info # Generate build information
./mvnw clean install -DskipTests # Skip tests during build- All Java Configuration: No XML configuration files
- Maven-based: Simplified dependency management
- Practical Approach: Hands-on coding and real-world examples
- Production-Ready: Learn industry best practices
journey
title Spring Boot Learning Journey
section Basics
Setup Environment : 5: Student
Create First App : 4: Student
Understand Structure : 3: Student
section Core Concepts
Dependency Injection : 4: Student
Auto Configuration : 3: Student
Properties Config : 5: Student
section Database
JPA/Hibernate : 3: Student
CRUD Operations : 4: Student
Query Methods : 3: Student
section Web Development
REST APIs : 4: Student
MVC Controllers : 3: Student
Thymeleaf Templates : 2: Student
section Advanced
Security : 2: Student
Testing : 3: Student
Microservices : 1: Student
⚡ Optimization Checklist:
├── 🚀 Use appropriate starter dependencies
├── 🎯 Configure connection pooling
├── 💾 Enable caching where appropriate
├── 📊 Monitor with Actuator metrics
├── 🔧 Profile-specific configurations
└── 🧪 Load testing in staging environment
Ctrl + Space- Code completionCtrl + Alt + O- Organize importsCtrl + Shift + F- Format codeAlt + Enter- Quick fix / show intentionsCtrl + D- Duplicate lineCtrl + Shift + Up/Down- Move statementCtrl + /- Toggle comment
Ctrl + Space- Content assistCtrl + Shift + O- Organize importsCtrl + Shift + F- Format codeCtrl + 1- Quick fixCtrl + Alt + Down- Duplicate line
Symptoms: ClassNotFoundException or port already in use
# Solution 1: Change port
server.port=8081
# Solution 2: Kill process using the port
# Linux/Mac: lsof -ti:8080 | xargs kill -9
# Windows: netstat -ano | findstr :8080 → taskkill /PID <PID>Solution:
./mvnw clean install -U # Force update of dependencies
./mvnw dependency:tree # Check dependency treeSolution:
- Enable build automatically: IntelliJ → Preferences → Compiler
- Enable auto-make: IntelliJ → Preferences → Advanced Settings
- Rebuild project:
Ctrl+Shift+F9
# Solution: Make sure endpoints are exposed
management.endpoints.web.exposure.include=*
management.endpoints.web.exposure.exclude=
# Verify endpoint: http://localhost:8080/actuator# application.properties
logging.level.root=INFO
logging.level.org.springframework=DEBUG
logging.level.org.springframework.boot=DEBUG
logging.level.com.myapp=DEBUG
# File-based logging
logging.file.name=app.log
logging.file.max-size=10MB
logging.file.max-history=30- Set Breakpoint: Click on line number (IntelliJ/Eclipse)
- Debug Mode: Right-click project → Debug As → Spring Boot App
- Step Through:
F6- Step overF5- Step intoF7- Step outF8- Resume
- F12 - Open DevTools in Chrome/Firefox
- Network Tab - Monitor API calls and responses
- Console Tab - Check for JavaScript errors
- Application Tab - View cookies and session storage
✅ Setup:
├── JDK 17+ installed
├── Maven installed or using wrapper
├── IDE configured with Spring plugins
└── Database drivers configured
✅ Development:
├── Spring Boot DevTools enabled
├── Logging configured
├── Properties externalized
└── Hot reload working
✅ Testing:
├── Unit tests written
├── Integration tests created
├── Mock external services
└── Test coverage > 70%
✅ Deployment:
├── Application packaged as JAR
├── Properties externalized for environments
├── Security configured
└── Database migrations planned
- Use Spring Profiles: Create
application-dev.properties,application-prod.propertiesfor different environments - Enable Build Cache: Speeds up Maven builds significantly
- Use VS Code REST Client: Install REST Client extension for easy API testing
- Monitor Memory: Use Actuator
/actuator/healthendpoint to monitor application health - Use Postman Collections: Export API collections from Postman for team collaboration
- Enable CORS Selectively: Don't use
@CrossOrigin("*")in production - Version Your APIs: Use URL versioning or header versioning for backward compatibility
- Document with Swagger/OpenAPI: Generate API documentation automatically
Happy Coding! 🚀
"The best way to learn Spring Boot is by building real applications. Start small, think big, and iterate often!" 💡