Skip to main content
This guide helps you diagnose and resolve common issues when developing and running the User Management API.

Common Issues

Error Message:
Web server failed to start. Port 8080 was already in use.
Solution 1: Kill the ProcessFind and kill the process using port 8080:
# Linux/macOS
lsof -ti:8080 | xargs kill -9

# Windows
netstat -ano | findstr :8080
taskkill /PID <PID> /F
Solution 2: Change the PortUpdate application.yaml or use an environment variable:
application.yaml
server:
  port: 8081
Or via command line:
./gradlew bootRun --args='--server.port=8081'
Error Message:
Connection to localhost:5432 refused. Check that the hostname and port are correct
and that the postmaster is accepting TCP/IP connections.
Cause: PostgreSQL is not running or not accessible.Solution 1: Start PostgreSQL
# Using Docker
docker run -d --name postgres \
  -e POSTGRES_DB=user_db \
  -e POSTGRES_USER=postgres \
  -e POSTGRES_PASSWORD=password \
  -p 5432:5432 \
  postgres:16

# Check if it's running
docker ps
Solution 2: Verify Connection SettingsCheck application.yaml or environment variables:
application.yaml
spring:
  datasource:
    url: jdbc:postgresql://localhost:5432/user_db
    username: postgres
    password: password
Solution 3: Use Docker Compose
docker compose up -d db
Error Message:
Unsupported class file major version 65
or
java.lang.UnsupportedClassVersionError
Cause: This project requires Java 21. You’re using an older version.Solution:
  1. Check your Java version:
java -version
  1. Install Java 21:
# Using SDKMAN!
sdk install java 21.0.2-tem
sdk use java 21.0.2-tem

# Using Homebrew (macOS)
brew install openjdk@21

# Verify installation
java -version
  1. Set JAVA_HOME:
# Linux/macOS
export JAVA_HOME=/path/to/java-21

# Windows
set JAVA_HOME=C:\Program Files\Java\jdk-21
Error Message:
FlywayException: Validate failed: Migration checksum mismatch for migration version 1
Cause: Database schema is out of sync with migration files.Solution 1: Repair Flyway
./gradlew flywayRepair
Solution 2: Clean and Rebuild (Development Only)
This will delete all data in your database. Only use in development!
# Drop and recreate database
docker exec -it postgres psql -U postgres -c "DROP DATABASE user_db;"
docker exec -it postgres psql -U postgres -c "CREATE DATABASE user_db;"

# Restart application
./gradlew bootRun
Solution 3: Baseline Existing Database
application.yaml
spring:
  flyway:
    baseline-on-migrate: true
    baseline-version: 0
Error Message:
Cannot resolve symbol 'UserDtoMapperImpl'
or
Could not autowire. No beans of 'UserDtoMapper' type found.
Cause: MapStruct annotation processor hasn’t generated implementation classes.Solution:
  1. Clean and rebuild the project:
./gradlew clean build
  1. Verify annotation processors are enabled in your IDE:
IntelliJ IDEA:
  • Settings → Build, Execution, Deployment → Compiler → Annotation Processors
  • Check “Enable annotation processing”
Eclipse:
  • Right-click project → Properties → Java Compiler → Annotation Processing
  • Check “Enable project specific settings”
  1. Rebuild the project:
./gradlew build --refresh-dependencies
Error Message:
Cannot resolve method 'builder()'
Cannot resolve method 'getUsername()'
Cause: Lombok plugin not installed or annotation processing disabled.Solution:
  1. IntelliJ IDEA:
    • Install Lombok plugin: Settings → Plugins → Search “Lombok” → Install
    • Enable annotation processing: Settings → Build → Compiler → Annotation Processors → Enable
    • Restart IDE
  2. Eclipse:
  3. VS Code:
    • Install “Lombok Annotations Support” extension
    • Reload window

Build Errors

Error Message:
Could not resolve all files for configuration ':compileClasspath'.
Solution:
# Clear Gradle cache
rm -rf ~/.gradle/caches/

# Refresh dependencies
./gradlew clean build --refresh-dependencies
Error Message:
Unable to start the daemon process.
Solution:
# Stop all Gradle daemons
./gradlew --stop

# Clear Gradle daemon directory
rm -rf ~/.gradle/daemon/

# Rebuild
./gradlew build
Error Message:
There were failing tests. See the report at: build/reports/tests/test/index.html
Solution:
  1. Run tests with verbose output:
./gradlew test --info
  1. Run specific test class:
./gradlew test --tests UserServiceTest
  1. Skip tests temporarily (not recommended):
./gradlew build -x test
  1. Check test reports:
open build/reports/tests/test/index.html

Runtime Errors

Error Message:
Error creating bean with name 'userService': Unsatisfied dependency expressed through constructor parameter 0
Cause: Spring cannot find a bean to inject.Solution:
  1. Check UserBeanConfiguration.java - ensure all required beans are defined:
src/main/java/com/fbaron/user/config/UserBeanConfiguration.java
@Bean
public UserJpaAdapter userJpaAdapter(UserJpaRepository repo, UserJpaMapper mapper) {
    return new UserJpaAdapter(repo, mapper);
}

@Bean
public UserService userService(UserQueryRepository queryRepo, 
                                UserCommandRepository cmdRepo) {
    return new UserService(queryRepo, cmdRepo);
}
  1. Verify component scanning is enabled (it should be by default with @SpringBootApplication).
  2. Check for circular dependencies - use constructor injection, not field injection.
Error Message: API returns 500 instead of 400 for invalid input.Cause: Missing @Valid annotation on controller method parameter.Solution:Ensure @Valid is present on DTO parameters:
src/main/java/com/fbaron/user/web/rest/UserRestAdapter.java
@PostMapping
public ResponseEntity<UserDto> registerUser(
        @Valid @RequestBody RegisterUserDto dto) {  // @Valid is required
    // Implementation...
}
Error Message: 404 Not Found when accessing /swagger-ui/index.htmlSolution:
  1. Verify the dependency is present in build.gradle:
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.8.15'
  1. Access the correct URL:
http://localhost:8080/swagger-ui/index.html
  1. Check if OpenAPI is configured in OpenApiConfig.java:
@Configuration
public class OpenApiConfig {
    @Bean
    public OpenAPI userManagementAPI() {
        // Configuration...
    }
}
Error Message:
Access to fetch at 'http://localhost:8080/api/v1/users' from origin 'http://localhost:3000' 
has been blocked by CORS policy
Solution:Add CORS configuration:
src/main/java/com/fbaron/user/config/WebConfig.java
package com.fbaron.user.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {
    
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/api/**")
                .allowedOrigins("http://localhost:3000")
                .allowedMethods("GET", "POST", "PUT", "DELETE")
                .allowedHeaders("*");
    }
}

Docker Issues

Error Message:
ERROR [build 6/6] RUN ./gradlew build
Solution:
  1. Ensure Dockerfile uses correct base image:
FROM eclipse-temurin:21-jdk-alpine AS build
  1. Check .dockerignore doesn’t exclude necessary files:
.git
build/
.gradle/
.idea/
  1. Build with no cache:
docker build --no-cache -t user-management-api .
Error Message:
docker ps shows container is not running
Solution:
  1. Check container logs:
docker logs <container-id>
  1. Ensure database is accessible from container:
# If using localhost, change to host.docker.internal (macOS/Windows)
# Or use Docker network
docker run -p 8080:8080 \
  -e SPRING_DATASOURCE_URL=jdbc:postgresql://host.docker.internal:5432/user_db \
  user-management-api
  1. Use Docker Compose for better networking:
docker compose up
Error Message:
Connection refused: connect
Cause: Container cannot reach PostgreSQL on localhost.Solution:Use Docker Compose and service names:
docker-compose.yml
services:
  db:
    image: postgres:16
    # ...
  
  api:
    build: .
    environment:
      SPRING_DATASOURCE_URL: jdbc:postgresql://db:5432/user_db  # Use service name
    depends_on:
      - db

Performance Issues

Solution:
  1. Enable SQL logging to identify slow queries:
application.yaml
spring:
  jpa:
    show-sql: true
    properties:
      hibernate:
        format_sql: true
logging:
  level:
    org.hibernate.SQL: DEBUG
    org.hibernate.type.descriptor.sql.BasicBinder: TRACE
  1. Add database indexes:
CREATE INDEX idx_users_email ON users(email);
CREATE INDEX idx_users_username ON users(username);
CREATE INDEX idx_users_active ON users(active);
  1. Use pagination for large result sets:
public interface UserJpaRepository extends JpaRepository<UserJpaEntity, UUID> {
    Page<UserJpaEntity> findAllByActiveTrue(Pageable pageable);
}
Solution:
  1. Limit JVM heap size:
./gradlew bootRun -Dorg.gradle.jvmargs="-Xmx512m -Xms256m"
  1. Use streaming for large datasets:
@Transactional(readOnly = true)
public Stream<User> findAllStream() {
    return userRepository.findAll().stream();
}
  1. Enable connection pooling in application.yaml:
spring:
  datasource:
    hikari:
      maximum-pool-size: 10
      minimum-idle: 2

Getting Help

Check Logs

Review application logs for detailed error messages:
./gradlew bootRun --info

Enable Debug Mode

Run with debug logging:
logging:
  level:
    com.fbaron.user: DEBUG

Review Documentation

Check the Spring Boot docs for framework-specific issues.

Community Support

Ask questions on Stack Overflow with the spring-boot tag.

Configuration Guide

Learn about application configuration options

Testing Guide

Write tests to catch issues early

Extending the App

Add new features correctly

Deployment

Deploy to production environments

Build docs developers (and LLMs) love