Swagger 修改默认配置

swagger配置

package com.sky.config;

import org.springframework.context.annotation.Configuration;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * 使用swagger需要创建一个配置类,并开启swagger配置
 * ps:swagger和 swagger2 不能通用
 *
 * 步骤:
 * 1.将swaggerConfig注册到ioc容器中
 * 2.开启swagger2功能
 * 3.运行项目,访问swagger-ui.html
 */
@Configuration // 就是@Component
@EnableSwagger2 // 开启swagger
public class Swagger2Config {
   
}

那我们要怎么更改swagger的默认配置呢?
先看 @EnableSwagger2

//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package springfox.documentation.swagger2.annotations;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.springframework.context.annotation.Import;
import springfox.documentation.swagger2.configuration.Swagger2DocumentationConfiguration;

@Retention(RetentionPolicy.RUNTIME)
@Target({
   ElementType.TYPE})
@Documented
@Import({
   Swagger2DocumentationConfiguration.class}) // 导入指定类
public @interface EnableSwagger2 {
   
}

该类的注解上有==@Import({Swagger2DocumentationConfiguration.class})==,导入了 Swagger2DocumentationConfiguration.class 这个类,继续看一下这个类是干哈的。

//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package springfox.documentation.swagger2.configuration;

import ...

@Configuration // 该类是一个配置类
@Import({
   SpringfoxWebMvcConfiguration.class, SwaggerCommonConfiguration.class})
@ComponentScan(
    basePackages = {
   "springfox.documentation.swagger2.mappers"}
)
@ConditionalOnWebApplication
public class Swagger2DocumentationConfiguration {
   
    public Swagger2DocumentationConfiguration() {
   
    }

    @Bean
    public JacksonModuleRegistrar swagger2Module() {
   
        return new Swagger2JacksonModule();
    }

    @Bean
    public HandlerMapping swagger2ControllerMapping(Environment environment, DocumentationCache documentationCache, ServiceModelToSwagger2Mapper mapper, JsonSeri
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值