swagger2的使用-123

1

	 
		org.springframework.boot
		spring-boot-starter-web
	
	
		io.springfox
		springfox-swagger2
		2.7.0
	
	
		io.springfox
		springfox-swagger-ui
		2.7.0
	

2
package com.vcloud.user;

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.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**

  • @author
  • 描述信息:
    /
    @Configuration //标记配置类
    @EnableSwagger2 //开启在线接口文档
    public class Swagger2Config {
    /
    • 添加摘要信息(Docket)
      */
      @Bean
      public Docket controllerApi() {
      return new Docket(DocumentationType.SWAGGER_2)
      .apiInfo(new ApiInfoBuilder()
      .title(“标题:支付功能的订单查询与订单关闭API文档”)
      .description(“描述:用于测试支付功能的订单查询与订单关闭”)
      .contact(new Contact(“PengYi”, null, null))
      .version(“版本号:1.0”)
      .build())
      .select()
      .apis(RequestHandlerSelectors.basePackage(“com.vcloud.user.controller.pay.client.order”))
      .paths(PathSelectors.any())
      .build();
      }
      }

3
package com.vcloud.user;

/**

  • @author PengYi 创建于 15:38 2020/8/18
  • 描述信息:
    **/

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.*;

@Configuration
public class WebMvcConfigurer extends WebMvcConfigurationSupport {

/**
 * @author 描述信息:
 **/
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
    registry.addResourceHandler("/**").addResourceLocations(
            "classpath:/static/");
    registry.addResourceHandler("swagger-ui.html").addResourceLocations(
            "classpath:/META-INF/resources/");
    registry.addResourceHandler("/webjars/**").addResourceLocations(
            "classpath:/META-INF/resources/webjars/");
    super.addResourceHandlers(registry);
}

}

你可能感兴趣的:(springboot)