Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to configure and disable swagger in springboot in production environment

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "how to configure disable swagger in springboot in production environment". The explanation in this article is simple and clear and easy to learn and understand. Please follow the editor's train of thought to study and learn "how to configure disable swagger in springboot in production environment".

I. Preface

In a production environment, we need to turn off the swagger configuration to avoid this dangerous behavior of exposing the interface.

2. Methods:

Disable method 1: use the annotation @ Profile ({"dev", "test"}) to indicate that it is on in the development or test environment and closed in production. (recommended)

Disable method 2: use the annotation @ ConditionalOnProperty (name = "swagger.enable", havingValue = "true") and then add swagger.enable = true to the test configuration or development configuration to turn it on. If the production environment is left empty, Swagger is turned off by default.

Such as method 1:

Package com.left

Import org.springframework.context.annotation.Bean

Import org.springframework.context.annotation.Configuration

Import springfox.documentation.builders.ApiInfoBuilder

Import springfox.documentation.builders.PathSelectors

Import springfox.documentation.builders.RequestHandlerSelectors

Import springfox.documentation.service.ApiInfo

Import springfox.documentation.spi.DocumentationType

Import springfox.documentation.spi.service.contexts.SecurityContext

Import springfox.documentation.spring.web.plugins.Docket

Import springfox.documentation.swagger2.annotations.EnableSwagger2

/ * *

*

* @ author: orange

* e-mail: 495314527@qq.com

* time: 14:49 on 2018-8-27

* desc: swagger configuration

* version: 1.0

*

, /

@ Configuration

@ EnableSwagger2

@ Profile ({"dev", "test"})

Public class Swagger2 {

@ Bean

Public Docket restApi () {

Return new Docket (DocumentationType.SWAGGER_2)

.select ()

.apis (RequestHandlerSelectors.basePackage ("com.left.controller"))

.notify (PathSelectors.any ())

.build ()

.apiInfo (apiInfo ())

}

Private ApiInfo apiInfo () {

Return new ApiInfoBuilder () .title ("springboot Integration swagger2")

.description ("springboot Integration swagger2")

.termsOfServiceUrl ("https://blog.csdn.net/weixin_37591536")"

.version ("1.0")

.build ()

}

}

Results:

The development environment can be accessed normally

Thank you for reading, the above is the content of "how to configure disable swagger in springboot in production environment". After the study of this article, I believe you have a deeper understanding of how to configure and disable swagger in springboot in production environment, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report