자신감 두보 배포 및 통합 (ⅱ) 액세스하여 RESTful 자신감

 

1. 의존 소개 자신감

<의존성>
  <의 groupId> io.springfox </의 groupId>
  <artifactId를> springfox-swagger2 </ artifactId를>
  <version>은 2.7.0 </ 버전>
</ 의존성>

 

2. 프로젝트에 다음 코드를 넣습니다

import org.springframework.context.annotation.Bean;

import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
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 SwaggerConfig {
  
    @Bean
    public Docket api() {
       return new Docket(DocumentationType.SWAGGER_2)
             .select()
             .apis(RequestHandlerSelectors.any())
             .build()
             .apiInfo(apiInfo());
    }
    
    private ApiInfo apiInfo() {
       return new ApiInfoBuilder()
             .title( "mserver接口API 文档" )
             .description( "HTTP对外开放接口" )
             .version( "1.0.0" )
             .build();
    }
  
}
 
3. 상기의 구성은 스프링 프로파일 클래스 도입

<bean class="test.SwaggerConfig"/>

4. 크로스 도메인 지원을 추가

<mvc:cors>   

     < mvc:mapping path = "/v2/api-docs" />   
</ mvc:cors
 
5. 시작 프로젝트 방문에 http : IP : 포트 / V2 / API-문서

추천

출처www.cnblogs.com/nuonuozhou/p/11389099.html