昂首阔步未检测到使用Spring Data Rest构建的Api [英] Swagger not detecting Api built with Spring Data Rest

查看:101
本文介绍了昂首阔步未检测到使用Spring Data Rest构建的Api的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用swagger生成用于我的API的文档的Spring Boot应用程序,正在使用Spring data rest生成Api,但是当我运行该应用程序时,我收到了swagger消息:未定义任何操作规格!

I'm working on a spring boot application using swagger to generate docs for my API ,I'm using Spring data rest to generate the Api but when I run the app I get the swagger message : No operations defined in spec!

这是我的Api代码:

@Api(tags = "projets")
@RepositoryRestResource(collectionResourceRel = "projets", path = "projets")
public interface IProjectRepository extends JpaRepository<Project, Long> {

}

这是我的配置文件:

@Configuration
@EnableSwagger2
public class QfactoryConfiguration {

    @Bean
     public Docket getDocketInstance() {
         return new Docket(DocumentationType.SWAGGER_2) 
                 .apiInfo(new ApiInfoBuilder()
                            .title("Spring Boot project")
                            .description("Spring Boot bootstrap project")
                            .version("0.1")
                            .license("Unlicense")
                            .build())
                  .select()  
                  .apis(RequestHandlerSelectors.basePackage("com.errabi.qfactory.repositories"))             
                  .paths(PathSelectors.any())                          
                  .build();  
     }




}

这是我正在使用的依赖项:

And this the dependencies that I'm using :

<dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger2</artifactId>
        <version>2.9.2</version>
    </dependency>

    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-data-rest</artifactId>
        <version>2.9.2</version>
    </dependency>
    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger-ui</artifactId>
        <version>2.9.2</version>
    </dependency>

我想问的是Swagger是否能够为Spring数据生成的Api生成文档,或者我应该使用带有注释@ Api,@ ApiOperation的@RestController

I'm asking is the Swagger is able to generate docs for Api generated by Spring data rest or I should use a @RestController with annotations @Api,@ApiOperation

我使用的是Spring Boot版本:2.1.3.RELEASE

I'm using spring boot version : 2.1.3.RELEASE

推荐答案

这帮了我大忙,升级到springfox的最新快照

This did the trick for me, upgrading to the latest snapshot of springfox

<dependencies>
...
<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger2</artifactId>
    <version>3.0.0-SNAPSHOT</version>
</dependency>
<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger-ui</artifactId>
    <version>3.0.0-SNAPSHOT</version>
</dependency>
<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-data-rest</artifactId>
    <version>3.0.0-SNAPSHOT</version>
</dependency>
...
</dependencies>

<repositories>
    <repository>
        <id>JFrog</id>
        <name>JFrog Snapshot Repository</name>
        <url>http://oss.jfrog.org/artifactory/oss-snapshot-local/</url>
    </repository>
</repositories>

然后使用 @ EnableSwagger2WebMvc 而不是 @ EnableSwagger2 :

@SpringBootApplication
@EnableSwagger2WebMvc
@Import(SpringDataRestConfiguration.class)
public class MyApplication {

    public static void main(String[] args) {
        SpringApplication.run(MyApplication.class, args);
    }

}

全部感谢 Yann39 .

这篇关于昂首阔步未检测到使用Spring Data Rest构建的Api的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆