我无法在Swagger-ui中看到我的JPAR存储库。谁能帮我?我只用@RestController Annotation看到我的类。当我将@RestController添加到我的JpaRepository时,它没有帮助。
Spring Boot版本1.5.10
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.8.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.8.0</version>
</dependency>
SwaggerConfig:
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build();
}
}
我的JpaRepository:
public interface ProductRepository extends JpaRepository<Product, Long>{
Optional<Product> findByCode(@Param("code") String code);
List<Product> findByStatusCode(@Param("statusCode") Integer statusCode, Pageable page);
}
通过GET进行HTTP调用 - ProductRepository:
/ 20180208132814
// http://localhost:8080/products
{
"_embedded": {
"products": [
{
"code": "yyyyy",
"statusCode": 0,
"mixed_rank": 9999999,
"offer_count": 0,
"maxPrice": null,
"minPrice": null,
"_links": {
"self": {
"href": "http://localhost:8080/products/1"
},
"product": {
"href": "http://localhost:8080/products/1"
},
"offers": {
"href": "http://localhost:8080/products/1/offers"
}
}
},
答案 0 :(得分:1)
我在这里找到了解决方案:https://reflectoring.io/documenting-spring-data-rest-api-with-springfox/它非常简单:)