Appearance
Fresh
Run tests
Back
Securing Spring Boot microservice using Keycloak and Testcontainers
Learn how to create an OAuth 2.0 Resource Server using Spring Boot, secure API endpoints with Keycloak, and test the application using the Testcontainers Keycloak module.
Java Testing with Docker
30 minutes
Run tests and next steps
Copy as Markdown
Open MarkdownAsk Docs AIClaudeOpen in Claude
Table of contents
Run the tests
console
$ ./mvnw testOr with Gradle:
console
$ ./gradlew testYou should see the Keycloak and PostgreSQL Docker containers start with the realm settings imported and the tests pass. After the tests finish, the containers stop and are removed automatically.
Summary
The Testcontainers Keycloak module lets you develop and test applications using a real Keycloak server instead of mocks. Testing against a real OAuth 2.0 provider that mirrors your production setup gives you more confidence in your security configuration and token-based authentication flows.
To learn more about Testcontainers, visit the Testcontainers overview.