Added Springfox Swagger-UI and it's not working, what am I missing?
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
When Springfox Swagger-UI does not load, the issue is usually configuration compatibility rather than missing UI files. The exact fix depends on your Spring Boot version and endpoint path setup. This guide covers a reliable diagnostic flow and working configurations for common setups.
Verify Version Compatibility First
Springfox has known compatibility limits with newer Spring Boot releases. Before changing code, confirm the version matrix in your project.
A practical rule of thumb:
- Spring Boot 2.x can often run with Springfox 3.0.0 plus configuration tweaks.
- Spring Boot 3.x projects generally work better with springdoc-openapi.
If you are on Boot 3 and starting fresh, migration to springdoc usually saves time.
Minimal Springfox Configuration Example
For a Boot 2.x project, start from a minimal Docket bean and confirm docs endpoint health before troubleshooting UI rendering.
After startup, test:
/v2/api-docs/swagger-ui//swagger-ui/index.html
If JSON docs endpoint fails, fix backend config first. UI depends on that endpoint.
Spring Boot 2.6 Path Matching Fix
A frequent issue is Boot 2.6 path matching changes. Add the matching strategy property when using Springfox.
Then restart and test docs endpoints again. This single property resolves many broken Swagger-UI setups on 2.6 and nearby versions.
Security and Reverse Proxy Considerations
If API docs endpoints are secured or behind a gateway, Swagger-UI may load but fail to fetch spec JSON.
Checklist:
- Permit access to docs endpoints in Spring Security.
- Ensure reverse proxy forwards correct path prefixes.
- Confirm CORS rules allow the UI origin.
Also inspect browser network logs. A 401, 403, or 404 on docs JSON usually identifies the root cause quickly.
Consider Migration to springdoc-openapi
If you are blocked by compatibility issues, migration can be simpler than patching around framework drift.
With springdoc, UI is typically available at /swagger-ui/index.html, and OpenAPI JSON at /v3/api-docs.
Quick Diagnostic Script
When debugging in a team environment, a repeatable check script saves time. Run these checks after each configuration change.
If docs JSON returns success but UI fails, inspect static resource mapping and proxy path rewriting. If docs JSON fails, focus on Spring config, security chain, and version compatibility first.
Also confirm no conflicting WebMvc configuration overrides default resource handlers. Custom MVC config classes can unintentionally disable Swagger-UI resource resolution.
Common Pitfalls
A common pitfall is checking only the UI page and ignoring whether the API spec endpoint is actually reachable. Another issue is mixing old and new Springfox annotations or dependencies in the same project, causing classpath confusion. Teams also often forget that security filters can block docs endpoints in non-local profiles. Finally, reverse proxy path rewriting can silently break relative links used by Swagger-UI. Validate behavior both directly on the app port and through the full gateway path to isolate where routing fails.
Summary
- Confirm Springfox and Spring Boot version compatibility first.
- Start with a minimal Docket config and test docs JSON endpoint directly.
- Apply path matching configuration for Boot 2.6 style issues.
- Verify security, CORS, and gateway routing for docs endpoints.
- Consider springdoc-openapi for newer Boot versions and simpler maintenance.
Related reading
- Adding header for HttpURLConnection
- Adding header to all request with Retrofit 2
- Adding Headers to Zuul when re-directing
- Adding n hours to a date in Java?
- Adding a Pool of Threads in a RxJava Flow
- Adding custom header using Spring Kafka
- Adding Tensorboard summaries from graph ops generated inside Dataset map function calls
- AFNetworking 2.0 add headers to GET request

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.