Spring boot 昂首阔步,@Configuration不';不能使用SpringFoxConfig

Spring boot 昂首阔步,@Configuration不';不能使用SpringFoxConfig,spring-boot,swagger,swagger-ui,openapi,Spring Boot,Swagger,Swagger Ui,Openapi,我使用SpringBoot框架,我试图用Swagger对我的API进行评论,但它不起作用。 我几乎可以肯定问题出在SpringFoxConfig配置类中 @EnableSwagger2 @Configuration public class SwaggerConfig { @Bean public Docket productApi() { return new Docket(DocumentationType.SWAGGER_2)

我使用SpringBoot框架,我试图用Swagger对我的API进行评论,但它不起作用。 我几乎可以肯定问题出在SpringFoxConfig配置类中

@EnableSwagger2
@Configuration
public class SwaggerConfig {


    @Bean
    public Docket productApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.techprimers.springboot.swaggerexample"))
                .paths(regex("/rest.*"))
                .build()
                .apiInfo(metaInfo());
    }

    private ApiInfo metaInfo() {

        ApiInfo apiInfo = new ApiInfo(
                "Spring Boot Swagger Example API",
                "Spring Boot Swagger Example API for Youtube",
                "1.0",
                "Terms of Service",
                new Contact("TechPrimers", "https://www.youtube.com/TechPrimers",
                        "techprimerschannel@gmail.com"),
                "Apache License Version 2.0",
                "https://www.apache.org/licesen.html"
        );

        return apiInfo;
    }
}
在我的POM文件中:

<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger2</artifactId>
    <version>2.6.1</version>
    <scope>compile</scope>
</dependency>

<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger-ui</artifactId>
    <version>2.6.1</version>
    <scope>compile</scope>
</dependency>

伊奥·斯普林福克斯
当我使用@Configuration运行它时,但当我删除@Configuration时,它会运行,当我键入它时,它不会向我显示任何东西(参见上图),因为我知道我希望他向我显示我在SpringFoxConfig类中编写的信息

你对我的问题有什么解决办法或解释吗


谢谢。

尝试在您的SwaggerConfig文件中替换这一行

API(RequestHandlerSelectors.any()) .path(路径选择器.any())

对于所有控制器方法

将其添加到WebSecurity配置类

@Configuration
public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter {

    @Override
    public void configure(WebSecurity web) throws Exception {
        web.ignoring().antMatchers("/v2/api-docs",
                                   "/configuration/ui",
                                   "/swagger-resources/**",
                                   "/configuration/security",
                                   "/swagger-ui.html",
                                   "/webjars/**");
    }

}

我在春天还是一个初学者,我不知道,而且我从来没有使用过WebSecurity配置。关于用RequestHandlerSelectors.any()和PathSelectors.any()替换.api和.path,它也不起作用(同样的问题),下面是我使用的所有导入:import org.springframework.context.annotation.Bean;导入org.springframework.context.annotation.Configuration;导入springfox.documentation.builders.PathSelector;导入springfox.documentation.builders.RequestHandlerSelectors;导入springfox.documentation.service.apinfo;导入springfox.documentation.service.Contact;导入springfox.documentation.spi.DocumentationType;导入springfox.documentation.spring.web.plugins.Docket;导入springfox.documentation.swagger 2.annotations.enableSawagger 2;试着这样做——检查您的pom中是否存在任何spring安全依赖项?我在教程中做了与他相同的事情。但我的问题是,当我找到这个问题的解决方案时,在我的情况下,它是由番石榴冲突引起的。一些依赖项依赖于Guava18.0,但是,Guava18中没有Fluentitable。所以我在这些依赖项中设置了execlusion,并添加了guava 20作为一个新的依赖项。