簡體   English   中英

在 Spring 數據 Rest 中,使用配置文件的 Swagger2 配置問題

[英]In Spring Data Rest, Swagger2 configuration issue by using profile

        <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>
@Profile({"dev-test", "local-test"})
@Configuration
@EnableSwagger2WebMvc
public class SwaggerConfig {

    @Bean
    public Docket documentation() {
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.any())
                .paths(s -> s.matches("/_api/.*"))
                .build();
    }
}

profile不是local-testdev-test 時會發生此錯誤。

***************************
APPLICATION FAILED TO START
***************************

Description:

Parameter 4 of constructor in springfox.documentation.spring.data.rest.EntityServicesProvider required a bean of type 'com.fasterxml.classmate.TypeResolver' that could not be found.


Action:

Consider defining a bean of type 'com.fasterxml.classmate.TypeResolver' in your configuration.

嗨,我正在使用Swagger3.0和 Spring 數據 Rest。

這是我引用的鏈接。 https://stackoverflow.com/a/46458135/10345277

我正在做的是嘗試通過配置文件打開或關閉 Swagger。

但是,與上面的鏈接不同,我使用 SDR 和springfox.documentation.spring.data.rest拋出錯誤。

有解決辦法嗎?

我的swagger3.0很好,像這樣:

@ConditionalOnClass(value = {Swagger.class})
@Profile({"dev", "test"})
@Configuration
@EnableSwagger2
public class SwaggerConfig {   
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("your base package"))
                .paths(PathSelectors.any())
                .build();
}

在我的例子中 - 使用 io.springfox:springfox-swagger2:2.9.2 和 io.springfox:springfox-swagger-ui:2.9.2 - 因為我忘記添加 @EnableSwagger2 到我的 @Configuration class 觸發了這個錯誤戰爭

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM