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();
        }
    }
    复制代码
  • 相关阅读:
    [NOIp pj 2007][Luogu P1095] 守望者的逃离
    [Noip 2009 普及组 T4] [Luogu P1070] 道路游戏
    跟风Manacher算法整理
    Luogu P2569 [SCOI2010] 股票交易
    qbzt2020五一DAY1T1集合——题解
    Cena使用教程
    2020.4.15校内测试
    康托展开学习笔记
    qbzt网格图路径问题——题解
    2-sat基础详解
  • 原文地址:https://www.cnblogs.com/leiqun123/p/11996180.html
Copyright © 2011-2022 走看看