zoukankan      html  css  js  c++  java
  • SpringBoot整合Swagger2以及生产环境的安全问题处理

    https://www.cnblogs.com/i-tao/p/10548181.html

    3.如果解决线上接口不被暴露?

     3.1 使用springboot security过滤

    略……

     3.2 生产环境移除Swagger2

    略……

     3.3 直接使用多环境配置,生产环境不启用Swagger2

    application.yml文件
    spring:
    profiles:
    active: pro

    application-pro.yml

    复制代码
    #生产环境
    server:
      port: 8080
    
    swagger2:
      enable: false
    复制代码

    2.2 Swagger2配置类增加

    @Value("${swagger2.enable}")
        private boolean swagger2Enable;
    复制代码
    package com.tao.springboot.util;
    
    import org.springframework.beans.factory.annotation.Value;
    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.spring.web.plugins.Docket;
    
    @Configuration
    public class Swagger2 {
        @Value("${swagger2.enable}")
        private boolean swagger2Enable;
    
        @Bean
        public Docket createRestApi() {
            return new Docket(DocumentationType.SWAGGER_2)
                    .enable(swagger2Enable)
                    .apiInfo(apiInfo())
                    .select()
                    .apis(RequestHandlerSelectors.basePackage("com.tao.springboot.action"))//controller路径
                    .paths(PathSelectors.any())
                    .build();
        }
    
        private ApiInfo apiInfo() {
            return new ApiInfoBuilder()
                    .title("标题")
                    .description("描述")
                    .termsOfServiceUrl("地址")
                    .version("1.0")
                    .build();
        }
    }
    复制代码
  • 相关阅读:
    POJ 3009
    POJ 3253
    POJ 3617
    POJ 3984
    UVA10012
    HDU5100
    HDU 5101
    UVA301 运输
    UVA 331 交换的方案数
    uva 10344 算23点
  • 原文地址:https://www.cnblogs.com/leiqun123/p/11996180.html
Copyright © 2011-2022 走看看