A comprehensive Spring Boot library providing common components, utilities, and auto-configurations for both WebMVC and WebFlux applications.
Platform Commons is a modular library that eliminates boilerplate code and provides battle-tested components for building robust Spring Boot microservices. It supports both traditional servlet-based (WebMVC) and reactive (WebFlux) applications.
πΉ spring-core
Core components shared across both WebMVC and WebFlux:
- Common exceptions and error handling
- DTOs (PageableDto, ServiceError)
- Constants (headers, MDC keys)
- Metrics collection
- Base annotations
π spring-boot-webmvc
Components for traditional Spring Boot WebMVC applications:
- starter: Auto-configuration for logging, security, exception handling, async support
- rest-client: RestTemplate-based REST client with OAuth2 support
- test-support: Testing utilities for WebMVC applications
Components for reactive Spring Boot WebFlux applications:
- starter: Auto-configuration for logging, security, exception handling
- rest-client: WebClient-based reactive REST client with OAuth2 support
- test-support: Testing utilities for WebFlux applications
Add the appropriate starter dependency to your build.gradle.kts:
For WebMVC applications:
dependencies {
implementation("io.github.platform:spring-boot-webmvc-starter:1.0.0")
}For WebFlux applications:
dependencies {
implementation("io.github.platform:spring-boot-webflux-starter:1.0.0")
}Simply add the dependency - auto-configuration handles the rest!
@SpringBootApplication
class MyApplication
fun main(args: Array<String>) {
runApplication<MyApplication>(*args)
}- Authorization annotation for method-level access control
- Header-based authorization (X-User-Groups)
- Configurable authorization aspect
- MDC (Mapped Diagnostic Context) support
- Transaction ID propagation
- Request/Response logging filters
- Async-safe logging with MDC context propagation
- Global exception handlers
- Standardized error responses
- Built-in exception types (ValidationException, ResourceNotFoundException, ForbiddenException, etc.)
- Micrometer-based metrics collection
- Auto-configuration for metrics
- Extensible metrics collector interface
- OAuth2-enabled REST clients
- Automatic token management and refresh
- Header propagation (transaction IDs, user context)
- Both sync (RestTemplate) and reactive (WebClient) implementations
- Externalized configuration support
- Sensible defaults
- Easy override via application.properties/yaml
platform:
security:
enabled: true # Enable/disable security features (default: true)platform:
rest-client:
oauth:
enabled: true
token-url: https://auth.example.com/oauth/token
client-id: your-client-id
client-secret: your-client-secret
grant-type: client_credentials
scope: read writelogging:
level:
io.github.platform.commons: DEBUG@RestController
@RequestMapping("/api/users")
class UserController {
@Authorization(authorizedGroups = ["admin", "manager"])
@GetMapping
fun getUsers(): List<User> {
// Only users in "admin" or "manager" groups can access
return userService.findAll()
}
}@Service
class UserServiceClient(
restTemplate: RestTemplate,
oAuthTokenManager: OAuthTokenManager?
) : AbstractRestClient(restTemplate, oAuthTokenManager) {
override fun getBaseUrl() = "https://api.example.com"
fun getUser(id: String): User {
return get("/users/$id", User::class.java).body!!
}
}@Service
class UserServiceClient(
webClient: WebClient,
baseUrl: String
) : AbstractReactiveRestClient(webClient, baseUrl) {
fun getUser(id: String): Mono<User> {
return get("/users/$id")
}
}@Service
class UserService {
fun getUser(id: String): User {
return userRepository.findById(id)
?: throw ResourceNotFoundException("User not found: $id")
}
}The global exception handler automatically converts this to a proper HTTP response:
{
"timestamp": "2025-11-02T10:30:00Z",
"status": 404,
"error": "Not Found",
"message": "User not found: 123",
"path": "/api/users/123"
}# Build all modules
make build
# Or using Gradle directly
./gradlew buildmake test# Format code (Spotless + removes unused imports via pre-commit)
make format
# Check formatting
make check-format# Install hooks (includes Spotless and ktlint for automatic formatting)
make pre-commit-install
# Run all pre-commit checks
make pre-commit-runmake publish-local- Java 21+
- Spring Boot 3.2.0+
- Kotlin 2.2.20+
- Gradle 9.2.0+
- Ensure all tests pass:
make test - Format code:
make format - Run pre-commit checks:
make pre-commit-run - Follow conventional commit messages
MIT License - see LICENSE file for details.
Balamurugan Elangovan Principal Software Engineer | Platform Engineering
GitHub | LinkedIn | mail.bala0224@gmail.com
For issues and questions, please open an issue on the GitHub repository.