Skip to content
Advertisement

Application failed after added swagger configuration

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

Advertisement

Answer

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>
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement