How to run Swagger 3 on Spring Boot 3
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
Spring Boot 3 uses Jakarta namespaces and newer framework internals, so older Swagger integrations often fail after an upgrade. The most stable path is to use the springdoc-openapi starter line built for Boot 3. Once dependencies, endpoint paths, and security rules are aligned, the Swagger UI works reliably in local and deployed environments.
Use a Boot 3 Compatible OpenAPI Library
If a project still uses older tooling, first remove incompatible Swagger dependencies. Then add one springdoc-openapi starter from the 2.x line.
Maven example:
Gradle example:
After adding the dependency, start the app and check:
- OpenAPI JSON:
/v3/api-docs - Swagger UI:
/swagger-ui/index.html
If those endpoints return data, the integration baseline is correct.
Minimal Controller and Annotation Example
You do not need heavy configuration to get started. A regular Spring REST controller with OpenAPI annotations is enough.
Run the application and confirm the endpoint appears in Swagger UI under the health tag.
Optional OpenAPI Metadata Configuration
For production-facing APIs, set title, version, and contact metadata so docs stay readable and auditable.
This bean is auto-detected and merged into generated docs.
Security Configuration for Documentation Endpoints
A frequent issue is "Swagger UI not loading" even though dependencies are correct. Usually Spring Security is blocking static UI assets or API docs endpoints.
Allow docs endpoints explicitly in your security chain:
In stricter environments, keep CSRF enabled for business endpoints and tune only doc access rules.
Property-Level Customization
You can customize paths and scanning behavior using application properties.
After this change:
- JSON endpoint becomes
/docs/api - UI endpoint becomes
/docs/ui
This is useful when API gateway routing conventions require specific prefixes.
Common Migration Notes
When upgrading from Spring Boot 2:
- Remove old
springfoxartifacts. - Confirm imports use
jakarta.*where required by Boot 3. - Re-test security path matchers because docs endpoints may be blocked after filter-chain refactors.
Most failures are dependency mismatch or security configuration, not OpenAPI annotations themselves.
Common Pitfalls
- Keeping outdated Swagger libraries that are incompatible with Spring Boot 3 internals.
- Expecting Swagger UI to load without allowing docs routes in Spring Security.
- Changing docs paths in properties but still opening the default URL.
- Mixing multiple OpenAPI libraries in one project, causing bean conflicts.
- Forgetting to re-run tests after Jakarta namespace migration.
Summary
- Use a Boot 3 compatible
springdoc-openapistarter from the 2.x line. - Verify
/v3/api-docsand/swagger-ui/index.htmlfirst before deeper tuning. - Add minimal annotations on controllers, then enrich metadata with an
OpenAPIbean. - Configure security to permit documentation routes explicitly.
- Treat migration work as dependency cleanup plus security path validation.

