2017-02-10 7 views
0

나는 Swagger를 사용하려고하는 스프링 부팅 1.5.1RELEASE 응용 프로그램이 있습니다. 다음봄 부팅 및 Swagger

compile group: 'io.springfox', name: 'springfox-swagger2', version: '2.5.0' 
compile group: 'io.springfox', name: 'springfox-swagger-ui', version: '2.5.0'compile('org.springframework.boot:spring-boot-devtools') 
compile("org.springframework.boot:spring-boot-starter-web:1.5.1RELEASE) 

그리고/설정 클래스 : 나는 종속성 추가

@Configuration 
@EnableSwagger2 
public class SwaggerConfig {  
    @Bean 
    public Docket api() {  
     return new Docket(DocumentationType.SWAGGER_2).select().apis(RequestHandlerSelectors.any()) 
         .paths(PathSelectors.any()).build();   
    }  

    private ApiInfo apiInfo() { 
     return new ApiInfoBuilder() 
         .title("My API Documentation ") 
         .description("Swagger API Documentation provided for your viewing pleasure") 
         .version("1.0") 
         .build(); 
    } 
} 

은 내가 http://localhost:3000/swagger-ui.html에서 내 API에 액세스 할 때

@Api(value = "/words", description = "Words API", produces = "application/json") 
@RestController 
@RequestMapping("/words") 
public class WordsController { 

@ApiOperation(value = "getAllWords", nickname = "getAllWords", 
       response = ResponseEntity.class, httpMethod = "GET") 
@ApiResponses(value = { 
       @ApiResponse(code = 200, message = "Success", response = ResponseEntity.class), 
       @ApiResponse(code = 500, message = "Failure") 
       }) 
@RequestMapping(method = RequestMethod.GET) 
@ResponseBody 
    public ResponseEntity getAllWords() { 
...} 

는하지만 (내가 가지고 GET 엔드 ​​포인트가 내 3000 번 포트에서 실행되도록 구성된 서버 녹색 스 내저 바를 가져옵니다. enter image description here

나는 몇 가지 자습서를이 떨어져 건물입니다,하지만 내 자신감 문서가

답변

0

제시되지 않는 이유는 볼 수없는이 구성 클래스에서 그 문제를 보인다, 아래의 자신감 구성 클래스

import static com.google.common.base.Predicates.or; 
import static springfox.documentation.builders.PathSelectors.regex; 
import com.google.common.base.Predicate; 

import springfox.documentation.builders.ApiInfoBuilder; 
import springfox.documentation.service.ApiInfo; 
import springfox.documentation.spi.DocumentationType; 
import springfox.documentation.spring.web.plugins.Docket; 
import springfox.documentation.swagger2.annotations.EnableSwagger2; 

/** 
* Sample Swgger config. 
* 
* @author Eranga 
*/ 
@Configuration 
@EnableSwagger2 
public class MySwaggerConfig { 

    /** 
    * Grouping only words api end points. 
    * 
    * @return the docket 
    */ 
    @Bean 
    public Docket myApi() { 
     return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select().paths(myApiPath()).build(); 
    } 

    /** 
    * Filtering only media activity api end points. 
    * 
    * @return the predicate 
    */ 
    private Predicate<String> myApiPath() { 
     return or(regex("//words.*")); 
    } 

    /** 
    * Api info. 
    * 
    * @return the api info 
    */ 
    private ApiInfo apiInfo() { 
     return new ApiInfoBuilder().title("My API title") 
       .description(
         "my Api desc") 
       .termsOfServiceUrl("http://erangakodikara.blogspot.com/").contact("Eranga") 
       .license("Apache License Version 2.0") 
       .licenseUrl("https://github.com/springfox/springfox/blob/master/LICENSE").version("2.0").build(); 
    } 
} 
+0

I와 시도 내 SwaggerConfig를 내 메인 클래스로 옮겨서 고쳐야한다고 생각합니다. 그래서 어떤 이유로이 @Configuration이 선택되지 않습니다. – sonoerin