pom依赖 

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

com.xuecheng.api.config.Swagger2Configuration.java

package com.xuecheng.api.config;

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;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

//
@Configuration
@EnableSwagger2
public class Swagger2Configuration {
    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.xuecheng"))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("学成网api文档")
                .description("学成网api文档")
//                .termsOfServiceUrl("/")
                .version("1.0")
                .build();
    }

}

@RestController 

swagger 测试

启动   http://localhost:31001/swagger-ui.html 

固定格式  地址后加:swagger-ui.html 

swagger 测试

相关文章:

  • 2022-12-23
  • 2021-06-15
  • 2021-12-29
  • 2022-12-23
  • 2022-12-23
  • 2021-07-29
  • 2021-07-12
  • 2021-06-16
猜你喜欢
  • 2022-12-23
  • 2021-11-15
  • 2021-09-22
  • 2021-10-06
  • 2021-07-24
相关资源
相似解决方案