2017-02-10 7 views
0

Ich habe eine Spring Boot 1.5.1RELEASE App, die ich Swagger mit verwenden möchte. Ich fügte hinzu, die Abhängigkeiten:Spring Boot und 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) 

Und dann ein/config Klasse:

@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(); 
    } 
} 

Ich habe einen GET Endpunkt

@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() { 
...} 

Aber wenn ich meine api in http://localhost:3000/swagger-ui.html zugreifen (Ich habe meine Server konfiguriert, um auf Port 3000 zu laufen Ich bekomme nur die grüne Prahlerei bar enter image description here

ich dieses Gebäude mehr Tutorials aus, aber ich kann nicht sehen, warum ist meine Swagger Dokumentation nicht

Antwort

0

in Ihrer Konfigurationsklasse sein ein Problem scheint präsentiert, versuchen Sie mit folgenden Prahlerei Konfigurationsklasse

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 Ich denke, ich habe es behoben, indem ich meine SwaggerConfig in meine Hauptklasse verschoben habe. Aus irgendeinem Grund wird diese @Configuration nicht abgeholt – sonoerin