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

发布于 2025-01-10 08:39:56 字数 2137 浏览 0 评论 0原文

我正在使用 spring boot,我想添加 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

在我的类中我添加了此方法:

      @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

I'm using spring boot and I want to add swagger configuration, the problem is after I run the application I get this error:

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

In my class I added this methods:

      @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();
        }

In my pom.xml I added this dependencies:

<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>

I can't understand what is wrong, I followed online solution asking me to add @EnableSwagger2WebMv and @EnableSwagger2 but I still get errors.
I tried to add @EnableSwagger2 in the SpringBootApplication and I get this error:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浮云落日 2025-01-17 08:39:56

我的应用程序正在工作,

@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>

My application is working that

@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();
    }

}

Also i added to application.properties this, but i added this because of spring version

spring.mvc.pathmatch.matching-strategy=ant_path_matcher

and i added these dependencies

<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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文