java - Spring Boot with Swagger - 看不到我的 JpaRepository

标签 java spring spring-boot swagger swagger-ui

我在 Swagger-ui 中看不到我的 JPARepositories。谁能帮我?我只看到带有 @RestController 注释的类。当我将 @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>

Swagger配置:

@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"
          }
        }
      },

最佳答案

我在这里找到了解决方案:https://reflectoring.io/documenting-spring-data-rest-api-with-springfox/太简单了:)

关于java - Spring Boot with Swagger - 看不到我的 JpaRepository,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48683959/

相关文章:

java - org.springframework.web.client.HttpClientErrorException 400 RestTemplate.postForEntity

java - 非法参数异常 : Type cannot be null

java - ObjectMapper 将日期更改为字符串

java - 当消费者抛出异常时如何使 JUnit 测试失败?

java - JPA:使用附加属性映射多对多关系

java - bean 类的属性 'maximumActive' 无效

java - 使用 JTDS 在 Spring Boot 中配置 HikariCP

java - 如何从 RestTemplate 作为列表访问数据

java - maven 没有为 spring boot 项目创建 META-INF

java - 为什么我的 while 进入无限循环?我如何解决它?