Spring-boot to disable swagger, spring-bootswagger

Source: Internet
Author: User

Spring-boot to disable swagger, spring-bootswagger

When using spring-boot for development, we often use swagger as the api documentation output. You can view the api path and parameters on the UI.

Of course, it is very convenient as a development environment, but we need to disable swagger in the production environment. How can I disable swagger through the configuration file?

The Code is as follows:

Import org. springframework. boot. autoconfigure. condition. conditionalOnProperty; import org. springframework. context. annotation. bean; import org. springframework. context. annotation. configuration; import springfox.doc umentation. builders. apiInfoBuilder; import springfox.doc umentation. builders. parameterBuilder; import springfox.doc umentation. builders. requestHandlerSelectors; import springfox.doc umentation. schema. modelRef; import springfox.doc umentation. service. parameter; import springfox.doc umentation. spi. documentationType; import springfox.doc umentation. spring. web. plugins. docket; import springfox.doc umentation. swagger2.annotations. enableSwagger2; import java. util. arrayList; import java. util. list;/*** Created by Bane. shi. * User: Bane. shi * Date: * Time: */@ Configuration @ ConditionalOnProperty (prefix = "swagger", value = {"enable"}, havingValue = "true ") @ EnableSwagger2public class SwaggerConfiguration {@ Bean public Docket swagger () {return new Docket (DocumentationType. SWAGGER_2 ). groupName ("default "). apiInfo (new ApiInfoBuilder (). title ("SSP School API "). version ("1.0.0 "). build ()). select (). apis (RequestHandlerSelectors. basePackage ("com. fclassroom. ssp. school ")). build (). globalOperationParameters ();} private List <Parameter> globalOperationParameters () {List <Parameter> parameters = new ArrayList <> (); // parameters. add (new ParameterBuilder (). name ("ACCESS-TOKEN "). description ("ACCESS-TOKEN "). required (false ). parameterType ("header "). modelRef (new ModelRef ("string ")). build (); return parameters ;}}

If you want to enable swagger, add

swagger.enable=true

The key is @ ConditionalOnProperty.

The attribute key here is swagger. enable, and havingValue is the expected value. It takes effect only when the value is equal to the expected value. That is to say, swagger. enable takes effect only when it is set to true. Other values or unspecified values will not take effect.

The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.