springboot学习 使用swagger3.0

当前swagger已经升级为3.0.0,主要更新如下:
Spring 5,Webflux 支持(仅请求映射支持,尚不支持功能端点)
Spring Integration 支持
Spring Boot 支持 springfox-boot-starter 依赖性(零配置,自动配置支持)
具有自动完成功能的文档化配置属性
更好的规范兼容性
支持 OpenApi 3.0.3
几乎零依赖性(唯一需要的库是 spring-plugin、pswagger-core)
现有的 swagger2 注释将继续有效,并丰富 open API 3.0 规范

  1. Maven pom依赖

注:此依赖可以不再使用

<dependency>
  <groupId>io.springfox</groupId>
  <artifactId>springfox-swagger2</artifactId>
  <version>3.0.0</version>
</dependency>
<dependency>
  <groupId>io.springfox</groupId>-->
  <artifactId>springfox-swagger-ui</artifactId>
  <version>3.0.0</version>
</dependency>

改为直接使用springfox-boot-starter依赖

<dependency>
  <groupId>io.springfox</groupId>
  <artifactId>springfox-boot-starter</artifactId>
  <version>3.0.0</version>
</dependency>

2、配置

去除swagger2的EnableSwagger2注解,使用@EnableOpenApi

package com.imooc;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.oas.annotations.EnableOpenApi;
/**
 * @author pei
 * @version 1.0
 * @date 2020/6/15 9:05 下午
 * @Description spring 启动类
 * http://localhost:8080/swagger-ui/index.html
 */
@RestController
@SpringBootApplication
@EnableOpenApi
public class DemoApplication {

    /**
     * @param args
     */
    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);

    }
}

3、配置

添加静态资源配置package com.iscas.biz.config;

package com.imooc.web.config;

import com.imooc.web.filter.TimeFilter;
import com.imooc.web.interceptor.TimeInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.AsyncSupportConfigurer;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

/**
 * @author pgw
 * @version 1.0
 * @date 2020/10/19 7:50 下午
 * @Description
 */
 
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.
                addResourceHandler("/swagger-ui/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/springfox-swagger-ui/")
                .resourceChain(false);
    }

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/swagger-ui/")
                .setViewName("forward:/swagger-ui/index.html");
    }
}

4、访问

http://localhost:8080/swagger-ui/index.html
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值