How to fully disable swagger-ui in spring-boot?(/swagger-ui.html should return 404)(如何在 spring-boot 中完全禁用 swagger-ui?(/swagger-ui.html 应该返回 404))
问题描述
I have read following topic: Disabling Swagger with Spring MVC
and I wrote:
But in case if I try to access swagger ui: localhost:8080/swagger-ui.html
I see
It looks not accurate. Can I fully disabled this URL ? 404 for example or something like this.
My answer is similar to the answer provided earlier with a slight difference. I usually create a separate spring profile named swagger
. When I want to enable Swagger, l pass the following VM flag while starting my application, -Dspring.profiles.active=swagger
. Here is an example of my Swagger configuration,
Next time when you try to access swagger-ui.html
without swagger
profile, you will get an empty Swagger screen but not 404.
If you don't want to load the static Swagger UI page at all, you can write a simple controller as shown below,
Now if you try to access swagger-ui.html
without swagger
profile, you will get a 404.
这篇关于如何在 spring-boot 中完全禁用 swagger-ui?(/swagger-ui.html 应该返回 404)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!