添加 swagger 配置后应用程序失败

Application failed after added swagger configuration

我正在使用 spring 启动并且我想添加 swagger 配置,问题是在我 运行 应用程序之后我得到这个错误:

org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration class [springfox.boot.starter.autoconfigure.OpenApiAutoConfiguration]; nested exception is java.io.FileNotFoundException: class path resource [springfox/documentation/spring/web/SpringfoxWebConfiguration.class] cannot be opened because it does not exist

在我的 class 中,我添加了这个方法:

      @Configuration
    public class SpringFoxConfig {
        @Bean
        public Docket api() {
            return new Docket(DocumentationType.SWAGGER_2)
                    .select()
                    .paths(input -> true)
                    .apis(input -> true)
                    .build()
                    .apiInfo(apiDetails());
        }
    
    
        private ApiInfo apiDetails() {
            return new ApiInfoBuilder()
                    .title("School Jpa")
                    .contact(new Contact("Robs","url", "email"))
                    .description("Crud Jpa sample")
                    .build();
        }

在我的 pom.xml 中,我添加了这个依赖项:

<dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-boot-starter</artifactId>
        <version>3.0.0</version>
    </dependency>
    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger-ui</artifactId>
        <version>2.9.2</version>
    </dependency>

我不明白哪里出了问题,我按照在线解决方案要求我添加 @EnableSwagger2WebMv@EnableSwagger2 但我仍然得到错误。 我试图在 SpringBootApplication 中添加 @EnableSwagger2,但出现此错误:

org.springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException: Cannot invoke "org.springframework.web.servlet.mvc.condition.PatternsRequestCondition.getPatterns()" because "this.condition" is null

我的应用程序正在运行

@SpringBootApplication
@EnableSwagger2
public class HrmsApplication {

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

    }
    @Bean
    public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.basePackage("KodlamaIo.hrms"))
                .build();
    }

}

我也添加到 application.properties 这个,但我添加这个是因为 spring 版本

spring.mvc.pathmatch.matching-strategy=ant_path_matcher

并且我添加了这些依赖项

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