2015-07-21 111 views
0

將Spring Data Rest添加到JHipster生成的項目後,如何使這些Rest API在控制器級別的API上可見?顯示Spring Data Rest的API

@RepositoryRestResource(collectionResourceRel = "api/myEntities", path = "api/myEntites") 

我也嘗試「/ api/myEntities」。

在Spring數據休息時,我就可以看到這些REST API的類似

​​

以下是我的項目中SwaggerConfiguration類。我看不出我如何定製它來顯示Spring Data Rest的API。

@Configuration 
@EnableSwagger2 
@Profile("!"+Constants.SPRING_PROFILE_PRODUCTION) 
public class SwaggerConfiguration implements EnvironmentAware { 

    private final Logger log = LoggerFactory.getLogger(SwaggerConfiguration.class); 

    public static final String DEFAULT_INCLUDE_PATTERN = "/api/.*"; 

    private RelaxedPropertyResolver propertyResolver; 

@Override 
public void setEnvironment(Environment environment) { 
    this.propertyResolver = new RelaxedPropertyResolver(environment, "swagger."); 
} 

/** 
* Swagger Springfox configuration. 
*/ 
@Bean 
public Docket swaggerSpringfoxDocket() { 
    log.debug("Starting Swagger"); 
    StopWatch watch = new StopWatch(); 
    watch.start(); 
    Docket docket = new Docket(DocumentationType.SWAGGER_2) 
     .apiInfo(apiInfo()) 
     .genericModelSubstitutes(ResponseEntity.class) 
     .forCodeGeneration(true) 
     .genericModelSubstitutes(ResponseEntity.class) 
     .directModelSubstitute(org.joda.time.LocalDate.class, String.class) 
     .directModelSubstitute(org.joda.time.LocalDateTime.class, Date.class) 
     .directModelSubstitute(org.joda.time.DateTime.class, Date.class) 
     .directModelSubstitute(java.time.LocalDate.class, String.class) 
     .directModelSubstitute(java.time.ZonedDateTime.class, Date.class) 
     .directModelSubstitute(java.time.LocalDateTime.class, Date.class) 
     .select() 
     .paths(regex(DEFAULT_INCLUDE_PATTERN)) 
     .build(); 
    watch.stop(); 
    log.debug("Started Swagger in {} ms", watch.getTotalTimeMillis()); 
    return docket; 
} 

/** 
* API Info as it appears on the swagger-ui page. 
*/ 
private ApiInfo apiInfo() { 
    return new ApiInfo(
     propertyResolver.getProperty("title"), 
     propertyResolver.getProperty("description"), 
     propertyResolver.getProperty("version"), 
     propertyResolver.getProperty("termsOfServiceUrl"), 
     propertyResolver.getProperty("contact"), 
     propertyResolver.getProperty("license"), 
     propertyResolver.getProperty("licenseUrl")); 
} 

}

+0

嘗試尋找在xx.xx.config.apidoc.SwaggerConfiguration.java – pmverma

+0

@pmverma感謝您的信息。我看不到如何更改類以獲取新添加的API。 – vic

回答

0

xx.xx.config.apidoc.SwaggerConfiguration.java

以下是默認的模式在SwaggerConfiguration包括這將顯示在您的管理標籤API。

public static final String DEFAULT_INCLUDE_PATTERN = "/api/.*";

而繼從相同類

.paths(regex(DEFAULT_INCLUDE_PATTERN))

線加入上述圖案。

因此,您可以添加另一個自己的,檢查Spring Data Rest api模式。並且像上面那樣在paths()函數中添加該api模式。

在這裏,我與jhipster交談2.18.0

+0

感謝您的信息。我知道了。它仍然不起作用。我在我的問題中提出了更多相關細節。 – vic

+0

@vic您是否嘗試過:http://docs.spring.io/spring-data/rest/docs/current/reference/html/#getting-started.basic-settings – pmverma

+0

嘗試添加'spring.data.rest。 basePath =/api' – pmverma