102

I am using spring data rest for my application.

I am getting following error and application doesn't get started when I add this method in repository:-

Method:-

@Modifying
@Transactional
@Query("from employee as ft where ft.company.id = ?1")
void deleteAllEmployeeCompany(
        @Param("companyId") @RequestParam("companyId") int companyId);

Error:-

org.springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException
    at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:176) ~[spring-context-4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:51) ~[spring-context-4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:346) ~[spring-context-4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:149) ~[spring-context-4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:112) ~[spring-context-4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:874) ~[spring-context-4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.finishRefresh(EmbeddedWebApplicationContext.java:144) ~[spring-boot-1.4.1.RELEASE.jar!/:1.4.1.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:544) ~[spring-context-4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.4.1.RELEASE.jar!/:1.4.1.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:761) [spring-boot-1.4.1.RELEASE.jar!/:1.4.1.RELEASE]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:371) [spring-boot-1.4.1.RELEASE.jar!/:1.4.1.RELEASE]

How to solve this ?

Updated:-

List of all dependencies:-

[INFO] com.test:test-service:jar:0.0.1-SNAPSHOT
[INFO] +- org.springframework.boot:spring-boot-starter-actuator:jar:1.4.1.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter:jar:1.4.1.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot:jar:1.4.1.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-autoconfigure:jar:1.4.1.RELEASE:compile
[INFO] |  |  \- org.springframework.boot:spring-boot-starter-logging:jar:1.4.1.RELEASE:compile
[INFO] |  |     +- ch.qos.logback:logback-classic:jar:1.1.7:compile
[INFO] |  |     |  \- ch.qos.logback:logback-core:jar:1.1.7:compile
[INFO] |  |     +- org.slf4j:jul-to-slf4j:jar:1.7.21:compile
[INFO] |  |     \- org.slf4j:log4j-over-slf4j:jar:1.7.21:compile
[INFO] |  \- org.springframework.boot:spring-boot-actuator:jar:1.4.1.RELEASE:compile
[INFO] |     \- org.springframework:spring-context:jar:4.3.3.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter-data-jpa:jar:1.4.1.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-aop:jar:1.4.1.RELEASE:compile
[INFO] |  |  \- org.springframework:spring-aop:jar:4.3.3.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-jdbc:jar:1.4.1.RELEASE:compile
[INFO] |  |  +- org.apache.tomcat:tomcat-jdbc:jar:8.5.5:compile
[INFO] |  |  |  \- org.apache.tomcat:tomcat-juli:jar:8.5.5:compile
[INFO] |  |  \- org.springframework:spring-jdbc:jar:4.3.3.RELEASE:compile
[INFO] |  +- org.hibernate:hibernate-core:jar:5.0.11.Final:compile
[INFO] |  |  +- org.jboss.logging:jboss-logging:jar:3.3.0.Final:compile
[INFO] |  |  +- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:jar:1.0.0.Final:compile
[INFO] |  |  +- antlr:antlr:jar:2.7.7:compile
[INFO] |  |  +- org.jboss:jandex:jar:2.0.0.Final:compile
[INFO] |  |  +- dom4j:dom4j:jar:1.6.1:compile
[INFO] |  |  |  \- xml-apis:xml-apis:jar:1.4.01:compile
[INFO] |  |  \- org.hibernate.common:hibernate-commons-annotations:jar:5.0.1.Final:compile
[INFO] |  +- org.hibernate:hibernate-entitymanager:jar:5.0.11.Final:compile
[INFO] |  +- javax.transaction:javax.transaction-api:jar:1.2:compile
[INFO] |  +- org.springframework.data:spring-data-jpa:jar:1.10.3.RELEASE:compile
[INFO] |  |  +- org.springframework.data:spring-data-commons:jar:1.12.3.RELEASE:compile
[INFO] |  |  +- org.springframework:spring-orm:jar:4.3.3.RELEASE:compile
[INFO] |  |  +- org.springframework:spring-tx:jar:4.3.3.RELEASE:compile
[INFO] |  |  +- org.springframework:spring-beans:jar:4.3.3.RELEASE:compile
[INFO] |  |  \- org.slf4j:jcl-over-slf4j:jar:1.7.21:compile
[INFO] |  \- org.springframework:spring-aspects:jar:4.3.3.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter-data-rest:jar:1.4.1.RELEASE:compile
[INFO] |  +- com.fasterxml.jackson.core:jackson-annotations:jar:2.8.3:compile
[INFO] |  +- com.fasterxml.jackson.core:jackson-databind:jar:2.8.3:compile
[INFO] |  |  \- com.fasterxml.jackson.core:jackson-core:jar:2.8.3:compile
[INFO] |  \- org.springframework.data:spring-data-rest-webmvc:jar:2.5.3.RELEASE:compile
[INFO] |     \- org.springframework.data:spring-data-rest-core:jar:2.5.3.RELEASE:compile
[INFO] |        \- org.atteo:evo-inflector:jar:1.2.1:compile
[INFO] +- org.springframework.boot:spring-boot-starter-web:jar:1.4.1.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-tomcat:jar:1.4.1.RELEASE:compile
[INFO] |  |  +- org.apache.tomcat.embed:tomcat-embed-core:jar:8.5.5:compile
[INFO] |  |  +- org.apache.tomcat.embed:tomcat-embed-el:jar:8.5.5:compile
[INFO] |  |  \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:8.5.5:compile
[INFO] |  +- org.hibernate:hibernate-validator:jar:5.2.4.Final:compile
[INFO] |  |  \- javax.validation:validation-api:jar:1.1.0.Final:compile
[INFO] |  +- org.springframework:spring-web:jar:4.3.3.RELEASE:compile
[INFO] |  \- org.springframework:spring-webmvc:jar:4.3.3.RELEASE:compile
[INFO] |     \- org.springframework:spring-expression:jar:4.3.3.RELEASE:compile
[INFO] +- org.springframework.cloud:spring-cloud-starter-eureka:jar:1.1.0.RELEASE:compile
[INFO] |  +- org.springframework.cloud:spring-cloud-starter:jar:1.1.0.RELEASE:compile
[INFO] |  |  +- org.springframework.cloud:spring-cloud-context:jar:1.1.0.RELEASE:compile
[INFO] |  |  |  \- org.springframework.security:spring-security-crypto:jar:4.1.3.RELEASE:compile
[INFO] |  |  +- org.springframework.cloud:spring-cloud-commons:jar:1.1.0.RELEASE:compile
[INFO] |  |  \- org.springframework.security:spring-security-rsa:jar:1.0.1.RELEASE:compile
[INFO] |  |     \- org.bouncycastle:bcpkix-jdk15on:jar:1.47:compile
[INFO] |  |        \- org.bouncycastle:bcprov-jdk15on:jar:1.47:compile
[INFO] |  +- org.springframework.cloud:spring-cloud-netflix-core:jar:1.1.0.RELEASE:compile
[INFO] |  +- org.springframework.cloud:spring-cloud-netflix-eureka-client:jar:1.1.0.RELEASE:compile
[INFO] |  +- com.netflix.eureka:eureka-client:jar:1.4.6:compile
[INFO] |  |  +- org.codehaus.jettison:jettison:jar:1.3.7:runtime
[INFO] |  |  |  \- stax:stax-api:jar:1.0.1:runtime
[INFO] |  |  +- com.netflix.netflix-commons:netflix-eventbus:jar:0.3.0:runtime
[INFO] |  |  +- com.netflix.archaius:archaius-core:jar:0.7.4:compile
[INFO] |  |  +- javax.ws.rs:jsr311-api:jar:1.1.1:runtime
[INFO] |  |  +- com.netflix.servo:servo-core:jar:0.10.1:runtime
[INFO] |  |  |  \- com.netflix.servo:servo-internal:jar:0.10.1:runtime
[INFO] |  |  +- com.sun.jersey:jersey-core:jar:1.19.1:runtime
[INFO] |  |  +- com.sun.jersey:jersey-client:jar:1.19.1:runtime
[INFO] |  |  +- com.sun.jersey.contribs:jersey-apache-client4:jar:1.19.1:runtime
[INFO] |  |  +- org.apache.httpcomponents:httpclient:jar:4.5.2:compile
[INFO] |  |  |  +- org.apache.httpcomponents:httpcore:jar:4.4.5:compile
[INFO] |  |  |  \- commons-codec:commons-codec:jar:1.10:compile
[INFO] |  |  +- com.google.inject:guice:jar:4.0:runtime
[INFO] |  |  |  +- javax.inject:javax.inject:jar:1:runtime
[INFO] |  |  |  \- aopalliance:aopalliance:jar:1.0:runtime
[INFO] |  |  \- com.netflix.governator:governator-api:jar:1.12.10:runtime
[INFO] |  +- com.netflix.eureka:eureka-core:jar:1.4.6:compile
[INFO] |  |  +- com.amazonaws:aws-java-sdk-core:jar:1.10.30:runtime
[INFO] |  |  +- com.amazonaws:aws-java-sdk-ec2:jar:1.10.30:runtime
[INFO] |  |  +- com.amazonaws:aws-java-sdk-autoscaling:jar:1.9.3:runtime
[INFO] |  |  +- com.amazonaws:aws-java-sdk-sts:jar:1.9.3:runtime
[INFO] |  |  +- com.amazonaws:aws-java-sdk-route53:jar:1.9.3:runtime
[INFO] |  |  +- com.netflix.governator:governator:jar:1.12.10:runtime
[INFO] |  |  |  +- com.netflix.governator:governator-core:jar:1.12.10:runtime
[INFO] |  |  |  \- org.ow2.asm:asm:jar:5.0.4:compile
[INFO] |  |  \- org.codehaus.woodstox:woodstox-core-asl:jar:4.4.1:runtime
[INFO] |  |     +- javax.xml.stream:stax-api:jar:1.0-2:runtime
[INFO] |  |     \- org.codehaus.woodstox:stax2-api:jar:3.1.4:runtime
[INFO] |  +- org.springframework.cloud:spring-cloud-starter-archaius:jar:1.1.0.RELEASE:compile
[INFO] |  |  \- commons-configuration:commons-configuration:jar:1.8:compile
[INFO] |  |     +- commons-lang:commons-lang:jar:2.6:compile
[INFO] |  |     \- commons-logging:commons-logging:jar:1.1.1:compile
[INFO] |  +- org.springframework.cloud:spring-cloud-starter-ribbon:jar:1.1.0.RELEASE:compile
[INFO] |  |  +- com.netflix.ribbon:ribbon:jar:2.1.5:compile
[INFO] |  |  |  +- com.netflix.ribbon:ribbon-transport:jar:2.1.5:runtime
[INFO] |  |  |  |  +- io.reactivex:rxnetty-contexts:jar:0.4.9:runtime
[INFO] |  |  |  |  \- io.reactivex:rxnetty-servo:jar:0.4.9:runtime
[INFO] |  |  |  \- io.reactivex:rxnetty:jar:0.4.9:runtime
[INFO] |  |  |     +- io.netty:netty-codec-http:jar:4.0.27.Final:runtime
[INFO] |  |  |     |  +- io.netty:netty-codec:jar:4.0.27.Final:runtime
[INFO] |  |  |     |  \- io.netty:netty-handler:jar:4.0.27.Final:runtime
[INFO] |  |  |     \- io.netty:netty-transport-native-epoll:jar:4.0.27.Final:runtime
[INFO] |  |  |        +- io.netty:netty-common:jar:4.0.27.Final:runtime
[INFO] |  |  |        +- io.netty:netty-buffer:jar:4.0.27.Final:runtime
[INFO] |  |  |        \- io.netty:netty-transport:jar:4.0.27.Final:runtime
[INFO] |  |  +- com.netflix.ribbon:ribbon-core:jar:2.1.5:compile
[INFO] |  |  +- com.netflix.ribbon:ribbon-httpclient:jar:2.1.5:compile
[INFO] |  |  |  \- com.netflix.netflix-commons:netflix-commons-util:jar:0.1.1:runtime
[INFO] |  |  +- com.netflix.ribbon:ribbon-loadbalancer:jar:2.1.5:compile
[INFO] |  |  |  \- com.netflix.netflix-commons:netflix-statistics:jar:0.1.1:runtime
[INFO] |  |  \- io.reactivex:rxjava:jar:1.1.5:compile
[INFO] |  +- com.netflix.ribbon:ribbon-eureka:jar:2.1.5:compile
[INFO] |  \- com.thoughtworks.xstream:xstream:jar:1.4.2:compile
[INFO] |     +- xmlpull:xmlpull:jar:1.1.3.1:compile
[INFO] |     \- xpp3:xpp3_min:jar:1.1.4c:compile
[INFO] +- org.springframework.boot:spring-boot-starter-amqp:jar:1.4.1.RELEASE:compile
[INFO] |  +- org.springframework:spring-messaging:jar:4.3.3.RELEASE:compile
[INFO] |  \- org.springframework.amqp:spring-rabbit:jar:1.6.2.RELEASE:compile
[INFO] |     +- com.rabbitmq:amqp-client:jar:3.6.3:compile
[INFO] |     +- org.springframework.retry:spring-retry:jar:1.1.4.RELEASE:compile
[INFO] |     +- com.rabbitmq:http-client:jar:1.0.0.RELEASE:compile
[INFO] |     \- org.springframework.amqp:spring-amqp:jar:1.6.2.RELEASE:compile
[INFO] +- com.netflix.hystrix:hystrix-javanica:jar:1.3.16:compile
[INFO] |  +- commons-collections:commons-collections:jar:3.2.2:compile
[INFO] |  +- org.aspectj:aspectjweaver:jar:1.8.9:compile
[INFO] |  +- com.google.guava:guava:jar:18.0:compile
[INFO] |  +- com.netflix.hystrix:hystrix-core:jar:1.5.2:compile
[INFO] |  |  \- org.hdrhistogram:HdrHistogram:jar:2.1.7:compile
[INFO] |  \- org.apache.commons:commons-lang3:jar:3.1:compile
[INFO] +- com.netflix.hystrix:hystrix-metrics-event-stream:jar:1.3.16:compile
[INFO] |  \- org.codehaus.jackson:jackson-core-asl:jar:1.9.2:compile
[INFO] +- io.springfox:springfox-swagger2:jar:2.6.0:compile
[INFO] |  +- io.swagger:swagger-annotations:jar:1.5.10:compile
[INFO] |  +- io.swagger:swagger-models:jar:1.5.10:compile
[INFO] |  +- io.springfox:springfox-spi:jar:2.6.0:compile
[INFO] |  |  \- io.springfox:springfox-core:jar:2.6.0:compile
[INFO] |  +- io.springfox:springfox-schema:jar:2.6.0:compile
[INFO] |  +- io.springfox:springfox-swagger-common:jar:2.6.0:compile
[INFO] |  +- io.springfox:springfox-spring-web:jar:2.6.0:compile
[INFO] |  +- com.fasterxml:classmate:jar:1.3.1:compile
[INFO] |  +- org.slf4j:slf4j-api:jar:1.7.21:compile
[INFO] |  +- org.springframework.plugin:spring-plugin-core:jar:1.2.0.RELEASE:compile
[INFO] |  +- org.springframework.plugin:spring-plugin-metadata:jar:1.2.0.RELEASE:compile
[INFO] |  \- org.mapstruct:mapstruct:jar:1.0.0.Final:compile
[INFO] +- io.springfox:springfox-swagger-ui:jar:2.6.0:compile
[INFO] +- io.springfox:springfox-data-rest:jar:2.6.0:compile
[INFO] |  \- org.springframework.hateoas:spring-hateoas:jar:0.20.0.RELEASE:compile
[INFO] +- org.liquibase:liquibase-core:jar:3.5.1:compile
[INFO] |  \- org.yaml:snakeyaml:jar:1.17:compile
[INFO] +- mysql:mysql-connector-java:jar:5.1.34:runtime
[INFO] +- org.springframework.boot:spring-boot-starter-test:jar:1.4.1.RELEASE:test
[INFO] |  +- org.springframework.boot:spring-boot-test:jar:1.4.1.RELEASE:test
[INFO] |  +- org.springframework.boot:spring-boot-test-autoconfigure:jar:1.4.1.RELEASE:test
[INFO] |  +- junit:junit:jar:4.12:test
[INFO] |  +- org.assertj:assertj-core:jar:2.5.0:test
[INFO] |  +- org.mockito:mockito-core:jar:1.10.19:test
[INFO] |  |  \- org.objenesis:objenesis:jar:2.1:test
[INFO] |  +- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] |  +- org.hamcrest:hamcrest-library:jar:1.3:test
[INFO] |  +- org.skyscreamer:jsonassert:jar:1.3.0:test
[INFO] |  |  \- org.json:json:jar:20140107:test
[INFO] |  +- org.springframework:spring-core:jar:4.3.3.RELEASE:compile
[INFO] |  \- org.springframework:spring-test:jar:4.3.3.RELEASE:test
[INFO] +- com.jayway.jsonpath:json-path:jar:2.2.0:compile
[INFO] |  \- net.minidev:json-smart:jar:2.2.1:compile
[INFO] |     \- net.minidev:accessors-smart:jar:1.1:compile
[INFO] \- org.reflections:reflections:jar:0.9.10:compile
[INFO]    +- org.javassist:javassist:jar:3.20.0-GA:compile
[INFO]    \- com.google.code.findbugs:annotations:jar:2.0.1:compile
Abderrazak BOUADMA
  • 1,526
  • 2
  • 16
  • 38
Galet
  • 5,853
  • 21
  • 82
  • 148

34 Answers34

216

I got same issue using springfox-swagger2 and springfox-swagger-ui version(3.0.0), spring-boot version(2.6.2)

The way to resolve this issue is by adding pathmatcher in application. properties or application.yml

for application.properties:

spring.mvc.pathmatch.matching-strategy = ANT_PATH_MATCHER

for application.yml:

spring:
    mvc:
      pathmatch:
            matching-strategy: ant_path_matcher
Santh
  • 2,221
  • 1
  • 5
  • 7
66

This issue is caused by Spring Fox 3.0.0 not supporting new PathPattern Based Path Matching Strategy for Spring MVC which is now the new default from spring-boot 2.6.0.

There are actually some workarounds for this issue like:

  1. Downgrading spring-boot back to version lower than 2.6.0. I wouldn't recommend that due to major security issues with older versions of spring boot / spring framework (like log4shell or CVE-2022-22965 for example.)
  2. Changing PathPattern matching back to AntPatternMatching in yml, like mentioned by @santhanam.
  3. SpringFox hasn't been updated for a year or so, so I would prefer remove it completely from a project and replace it with maintained springdoc-openapi library. There is a section in springdoc documentation about migration from SpringFox and it's actually very straightforward to perform. And you'll get rid of issues caused by SpringFox completely.
Michał Stochmal
  • 5,895
  • 4
  • 36
  • 44
  • 6
    Suggestion 3 should be the accepted answer IMO. Depending on a project that hasn't had attention in almost two years is not a wise move. As of now, no commits have been made on SpringFox since Oct 2020. – teuber789 Mar 19 '22 at 01:40
  • 2
    #3 is the best solution and I can confirm that the migration is indeed straight forward – Younes El Ouarti Apr 07 '22 at 05:25
  • 1
    Be careful with downgrading sping-boot since it may contain the old log4j versions with a serious exploid to JNDI-calls... – Benvorth Jun 03 '22 at 06:43
  • 2
    Whenever I read "downgrade", it makes my stomach turn. – html_programmer Jun 04 '22 at 19:13
28

what I found was that spring is using mvcmatchers by default which conflicts with swagger because it uses the antmatchers so we can solve this by

A

change spring to use antmatchers with configuring it in application.properties

spring.mvc.pathmatch.matching-strategy = ANT_PATH_MATCHER

B

enabling mvcmatchers in spring creating a config file for swagger to use

  1. create a file for configs of swagger in anywhere you want
  2. put these annotations
@EnableWebMvc
@EnableSwagger2
@Component
public class SwaggersConfigs {
}

C

enableing mvcmatchers in all spring application with putting @EnableWebMvc annotation above the main class of spring boot aplication like this


@EnableWebMvc
@EnableSwagger2
@SpringBootApplication
public class SwaggerDemoApplication {

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

}

D

use older versions metioned in the other comments

24

I got same issue using springfox-swagger2 and springfox-swagger-ui Switching back spring boot version from 2.6.0 to 2.5.2 Solved my issue.

I know rolling back to older versions is not the best way to fix issues but helped me for now.

Affes Salem
  • 1,303
  • 10
  • 26
  • 1
    it solved my problem :) thank you – Kushwaha Dec 01 '21 at 11:54
  • 1
    It solved my problem. Thanks! – PKS Dec 06 '21 at 04:44
  • 2
    Yeah, that's the thing. This happened to me with open-api-generator integration which uses springfox for their implementations. I even I tried with spring boot version 2.6.2 updating springfox-swagger2 and springfox-swagger-ui to the latest versions 3.0.x. No luck. Had to roll back to Spring boot 2.5.4 and 2.9.2 version of springfox. Hope in the future they fix this – ChamaraL Jan 07 '22 at 06:36
  • 2
    spring boot 2.6.2 includes the recommended log4j 2.17 so this really needs to be fixed – Mark Jan 07 '22 at 12:10
  • 1
    it solved my problem, thanks. Changed the version as follows : org.springframework.boot spring-boot-starter-parent 2.5.6 – cem çetin Feb 12 '22 at 17:36
  • With the new vulnerability Spring4Shell this solution is no longer a valid option. – daniloquio Apr 05 '22 at 18:33
11

this works Springboot version 2.6.0 and higher does not support swagger 2 Remove springfox and swagger 2 dependencies. Add springdoc-openapi-ui dependency instead.

    <dependency>
        <groupId>org.springdoc</groupId>
        <artifactId>springdoc-openapi-ui</artifactId>
        <version>1.6.6</version>
    </dependency>

add this to your application.properties file

spring.mvc.pathmatch.matching-strategy = ANT_PATH_MATCHER

after that navigate to http://localhost:8080/swagger-ui/index.html

This worked for me

10

The reason for the error is swagger and spring-boot The version does not match

Remove All other dependencies and include only below one for swagger

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

Add below Configurations :

For application.properties

spring.mvc.pathmatch.matching-strategy = ANT_PATH_MATCHER

For application.yml

spring:
    mvc:
      pathmatch:
            matching-strategy: ant_path_matcher
10

This solution fixed the issue along with the below property

spring.mvc.pathmatch.matching-strategy=ant_path_matcher

I'm using spring boot 2.6.6

Vijay Rajendran
  • 101
  • 1
  • 2
8

In addition to setting the matching-strategy property, as mentioned by other answers, I also had to add the below bean to overcome this:

@Bean
public WebMvcEndpointHandlerMapping webEndpointServletHandlerMapping(WebEndpointsSupplier webEndpointsSupplier, ServletEndpointsSupplier servletEndpointsSupplier, ControllerEndpointsSupplier controllerEndpointsSupplier, EndpointMediaTypes endpointMediaTypes, CorsEndpointProperties corsProperties, WebEndpointProperties webEndpointProperties, Environment environment) {
    List<ExposableEndpoint<?>> allEndpoints = new ArrayList();
    Collection<ExposableWebEndpoint> webEndpoints = webEndpointsSupplier.getEndpoints();
    allEndpoints.addAll(webEndpoints);
    allEndpoints.addAll(servletEndpointsSupplier.getEndpoints());
    allEndpoints.addAll(controllerEndpointsSupplier.getEndpoints());
    String basePath = webEndpointProperties.getBasePath();
    EndpointMapping endpointMapping = new EndpointMapping(basePath);
    boolean shouldRegisterLinksMapping = this.shouldRegisterLinksMapping(webEndpointProperties, environment, basePath);
    return new WebMvcEndpointHandlerMapping(endpointMapping, webEndpoints, endpointMediaTypes, corsProperties.toCorsConfiguration(), new EndpointLinksResolver(allEndpoints, basePath), shouldRegisterLinksMapping, null);
}


private boolean shouldRegisterLinksMapping(WebEndpointProperties webEndpointProperties, Environment environment, String basePath) {
    return webEndpointProperties.getDiscovery().isEnabled() && (StringUtils.hasText(basePath) || ManagementPortType.get(environment).equals(ManagementPortType.DIFFERENT));
}

Solution found here.

Vlad
  • 844
  • 1
  • 12
  • 22
7

I have got the same issue in spring boot version 1.5.3.RELEASE, but could resolve it by adding guava version 20.0.

    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
        <version>20.0</version>
    </dependency>
    <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>
gvk
  • 156
  • 1
  • 8
7

With Spring-Boot 2.6.0 and SpringFox 3.0.0 issue is pathmatcher, you can set pathmach with below property and this issue will be resolved

  spring:
        mvc:
          pathmatch:
                matching-strategy: ant_path_matcher
Kailas010
  • 345
  • 4
  • 5
6

Just add this configuration to your application.properties

spring.mvc.pathmatch.matching-strategy = ANT_PATH_MATCHER

or if you using yaml file application.yml

spring:
mvc:
  pathmatch:
        matching-strategy: ant_path_matcher

then Run your application.

You need to edit one part, the base package name. As shown in the screenshot my base package name. my package name

@Configuration
@EnableSwagger2
public class SwaggerConfig2 {
    @Bean
    public Docket docket() {
        return new Docket(DocumentationType.SWAGGER_2)
                .enable(true)
                .apiInfo(new ApiInfoBuilder()
                        .title("Swagger Super")
                        .description("Swagger Description details")
                        .version("1.0").build())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.example.swagger.controller"))
                .paths(PathSelectors.any()).build();
    }
}

OR

@Configuration
@EnableSwagger2
public class SwaggerConfig2 {
    @Bean
    public Docket docket() {
        return new Docket(DocumentationType.SWAGGER_2)
                .enable(true)
                .apiInfo(new ApiInfoBuilder()
                        .title("Swagger Super")
                        .description("Swagger Description details")
                        .version("1.0").build())
                .select()
                .apis(RequestHandlerSelectors.withClassAnnotation(Api.class))
                .paths(PathSelectors.any()).build();
    }
}

And the Swagger Dependencies

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

It's working fine

Also, you can define separately

@Configuration
@EnableSwagger2
public class Swagger2UiConfiguration {
    @Bean
    public Docket api() {
        return (new Docket(DocumentationType.SWAGGER_2)).apiInfo(this.apiInfo()).select().apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class)).paths(PathSelectors.any()).build();
    }

    private ApiInfo apiInfo() {
        return (new ApiInfoBuilder()).title("Swagger API").version("1.0").description("Swagger is Awesome").build();
    }
}

Note: SNAPSHOT, M1, M2, M3, and M4 releases typically WORK IN PROGRESS. The Spring team is still working on them, Recommend NOT using them.

Note: If want to implement springdoc-openAPI for the new version spring-boot 3 then use the below-following dependency. That specific version would be working with spring boot 3

        <dependency>
            <groupId>org.springdoc</groupId>
            <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
            <version>2.0.2</version>
        </dependency>

I hope this helps! Let me know if you have any questions or if there's anything else I can assist you with.

Happy coding! ‍

Fazal Haroon
  • 845
  • 2
  • 10
  • 20
5

removing old swagger dependencies and config classes. using new springdoc dependency will help

    <dependency>
        <groupId>org.springdoc</groupId>
        <artifactId>springdoc-openapi-ui</artifactId>
        <version>1.6.4</version>
    </dependency>
vamshi vishnu
  • 51
  • 1
  • 1
4

a work around is to rollback to springfox-swagger2 2.5.0 .

Abderrazak BOUADMA
  • 1,526
  • 2
  • 16
  • 38
  • 3
    For me, the newest working version of springfox-swagger2 is 2.8.0, so try rollbacking to that version. Works in combination with the newest released version of springfox-swagger-ui 2.9.2. – Mate Šimović Jul 10 '18 at 11:07
  • 15
    How a documentation tool can murder an application is totally beyond me. Irresponsible. – html_programmer Sep 01 '21 at 21:28
  • Thank you so much @MateŠimović the 2.8.0 thing worked for me with springfox-swagger-ui-2.9.2 and spring-boot-starter-parent 2.6.2!! – Yash Nasery Jan 24 '22 at 08:59
4

As per official doc, adding below property in yaml resolved the issue for me.

springfox:
  documentation:
    auto-startup: false
cigien
  • 57,834
  • 11
  • 73
  • 112
Jestino Sam
  • 526
  • 2
  • 12
  • 31
  • 1
    This will fix the app starting issue but springfox will stop working ;). I think the only thing to do is to wait for a patch to springfox. – Michał Stochmal Jan 21 '22 at 09:35
2

i got similar issue and it was solved after follow Springboot 2.6.0 / Spring fox 3 - Failed to start bean 'documentationPluginsBootstrapper'

i was using spring 2.6.1 and springfox-swagger2 2.9.2. "setting spring.mvc.pathmatch.matching-strategy to ant-path-matcher in your application.properties file"

Liang Zong
  • 61
  • 6
  • 3
    Just to add this will not work if spring boot actuator dependency is there. I had to remove the actuator dependency (losing the actuator endpoints of course). and after adding this property with swagger version(s) up to 3.0.0 this worked – M. Amer Dec 19 '21 at 18:00
2

With Spring-Boot 2.6.2 issue is pathmatcher, you can set pathmach with below property in application.properties file and this issue will be resolved

"spring.mvc.pathmatch.matching-strategy = ANT_PATH_MATCHER"

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 27 '21 at 22:16
2

I added @EnableWebMvc as decorator to my SwaggerConfig, which solved to problem.

@EnableWebMvc
public class SwaggerConfig {}

Versions: Sprint 2.6.1 and springfox-swagger* 2.9.2

1

For me the issue seemed to be attempting to pass in an argument to a controller action (for a controller annotated with RestController) that was not getting resolved.

e.g.

@ResponseBody
@PostMapping(value = "/foo")
com.bestbuy.checkout.domain.Order foo(
    Bar justSomeObject
) {
Igor
  • 33,276
  • 14
  • 79
  • 112
1

As per : https://github.com/springfox/springfox/issues/2616 solution, I tried adding exclusion to recently added Lettuce library and it is working fine now. Only springfox guava dependency should be coming. As per this question something like below will work:

<dependency>
    <groupId>com.netflix.hystrix</groupId>
    <artifactId>hystrix-javanica</artifactId>
    <version>1.3.16</version>
        <exclusions>
            <exclusion>
                <groupId>com.google.guava</groupId>
                <artifactId>guava</artifactId>
            </exclusion>
        </exclusions>
</dependency>
Ankush
  • 499
  • 1
  • 7
  • 17
1

I also had an issue like that in gradle. I solved it by removing all guava dependencies from springfox subdependecies:

implementation('io.springfox:springfox-spi:2.9.2') {
    exclude group: 'com.google.guava', module: 'guava'
}

implementation('io.springfox:springfox-schema:2.9.2') {
    exclude group: 'com.google.guava', module: 'guava'
}

implementation('io.springfox:springfox-spring-web:2.9.2') {
    exclude group: 'com.google.guava', module: 'guava'
}

and implemented guava separately:

implementation('com.google.guava:guava:28.1-jre')

My spring-boot version:

2.5.0-SNAPSHOT

1

Reducing the version of my project helped me. Initially, I was using spring 2.6.0 but I moved to 2.5.2 and it solves the issue.

PKS
  • 618
  • 1
  • 7
  • 19
1

The general reason is that due to the springboot versioning, the default strategy for matching the request path and spring MVC processing mapping has been changed from antpathmatcher to pathpatternparser. This can be resolved by editing the properties.yml and adding

spring: mvc: pathmatch: matching-strategy: ant_path_matcher

MikeMopo
  • 11
  • 2
1

If you are using spring boot 2.6 and trying to use springfox-swagger you will have a hard time.

If you are trying to have swagger documentation just use this dependency

implementation 'org.springdoc:springdoc-openapi-ui:1.6.4'

it will generate the doc for you that you can access using /v3/api-docs and the swagger-ui is accessible using /swagger-ui/index.html

Hope this helps someone.

moolsbytheway
  • 1,152
  • 13
  • 20
1

change spring to use antmatchers with configuring it in application.properties in your spring boot project.

spring.mvc.pathmatch.matching-strategy = ANT_PATH_MATCHER
Procrastinator
  • 2,526
  • 30
  • 27
  • 36
0

Change your query to

@Modifying
@Transactional
@Query("from employee as ft where ft.company.id = :companyId")
void deleteAllEmployeeCompany(
        @Param("companyId") @RequestParam("companyId") int companyId);

Or with SpEL

@Modifying
@Transactional
@Query("from employee as ft where ft.company.id = ?#{companyId}")
void deleteAllEmployeeCompany(
        @Param("companyId") @RequestParam("companyId") int companyId);

Check this https://spring.io/blog/2014/07/15/spel-support-in-spring-data-jpa-query-definitions

Issam El-atif
  • 2,366
  • 2
  • 17
  • 22
  • I have tried your answer. But it results with same error. – Galet Oct 26 '16 at 06:44
  • I think the issue is related to spring-fox not to spring-data. `documentationPluginsBootstrapper` is a spring-fox component. What version of spring-fox are you using? – Issam El-atif Oct 26 '16 at 07:19
  • I am not using spring-fox in my application. – Galet Oct 26 '16 at 07:42
  • https://github.com/springfox/springfox/blob/master/springfox-spring-web/src/main/java/springfox/documentation/spring/web/plugins/DocumentationPluginsBootstrapper.java – Issam El-atif Oct 26 '16 at 08:21
  • Please share the list of all dependencies. – Issam El-atif Oct 26 '16 at 09:01
  • As you can see you have this dependencies : io.springfox:springfox-swagger2:jar:2.6.0:compile [INFO] | +- io.swagger:swagger-annotations:jar:1.5.10:compile [INFO] | +- io.swagger:swagger-models:jar:1.5.10:compile [INFO] | +- io.springfox:springfox-spi:jar:2.6.0:compile [INFO] | | \- io.springfox:springfox-core:jar:2.6.0:compile [INFO] | +- io.springfox:springfox-schema:jar:2.6.0:compile [INFO] | +- io.springfox:springfox-swagger-common:jar:2.6.0:compile ... – Issam El-atif Oct 26 '16 at 09:35
  • Are you using swagger to document your api? If not remove these dependencies `io.springfox:springfox-swagger2` `io.springfox:springfox-swagger-ui` `io.springfox:springfox-data-rest` – Issam El-atif Oct 26 '16 at 09:41
  • Yes. I am using swagger for API. Then how to proceed ? – Galet Oct 26 '16 at 09:56
  • Can you share spring configuration? – Issam El-atif Oct 26 '16 at 12:24
  • What do you mean by spring configuration ? – Galet Oct 26 '16 at 13:15
  • Configuration class where your added `@EnableWebMvc` and `@EnableSwagger2` – Issam El-atif Oct 26 '16 at 13:32
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/126796/discussion-between-karan-and-issam-el-atif). – Galet Oct 27 '16 at 07:45
  • I run with the same issue and rollback to springfox 2.5.0 solves the issue (at least the application starts and every thing is okey). It looks that there's a bug intorudcued sine 2.6.0 of springfox – Abderrazak BOUADMA Dec 07 '16 at 12:48
0

I have a mircoservice environment, and I was adding swagger to all of them. I had the same issue, the solution @Santhanam worked for all the services except one. The service had spring-boot-starter-actuator as a dependency. Problem fixed by removing it.

It seems the config spring.mvc.pathmatch.matching-strategy = ANT_PATH_MATCHER does not affect Spring Actuator auto-generated paths.

For those who tried other answers and still have the problem, the solution is to remove Spring Actuator or to configure it in a way to use ANT_PATH_MATCHER as matching strategy.

Ahmad Jahanbin
  • 301
  • 3
  • 7
0

I solved the issue easily. What we need to know is that Spinifex is no more up to date For more info click on this link. Nowadays, you can use spring-doc, by remplacing spring-fox dependencies with this dependency :

<dependency>
      <groupId>org.springdoc</groupId>
      <artifactId>springdoc-openapi-ui</artifactId>
      <version>1.6.8</version>
</dependency>

then add also this beans :
@Bean
    public GroupedOpenApi publicApi() {
        return GroupedOpenApi.builder()
                .group("springshop-public")
                .pathsToMatch("/public/**")
                .build();
    }
    @Bean
    public GroupedOpenApi adminApi() {
        return GroupedOpenApi.builder()
                .group("springshop-admin")
                .pathsToMatch("/**")
                .build();
    }
4b0
  • 21,981
  • 30
  • 95
  • 142
  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 09 '22 at 18:40
0

I am using 2.7.6 version of spring boot and I was getting the same error. So I found the solution and check this; Failed to start bean ‘documentationPluginsBootstrapper’ – use springdoc-openapi-ui

I added openapi dependency to my pom.xml file:

<dependency>
    <groupId>org.springdoc</groupId>
    <artifactId>springdoc-openapi-ui</artifactId>
    <version>1.6.9</version>
</dependency>

Also added matching-strategy to my application.preperties or application.yml file;

spring.mvc.pathmatch.matching-strategy = ANT_PATH_MATCHER
Semih Erkaraca
  • 146
  • 1
  • 6
0

I resolve this issue in Spring Boot 2.1.6.RELEASE and Spring Fox 3.0.0 just adding this dependency:

<dependency>
        <groupId>org.springframework.plugin</groupId>
        <artifactId>spring-plugin-core</artifactId>
        <version>2.0.0.RELEASE</version>
</dependency>
0

For me the issue was with the spring actuator and I have upgraded my spring version to 2.7.1 Removing the spring actuator helped.

Debo
  • 1
0

Mine was fixed by below, during upgrade to 2.7 we have added docs profile in Application properties file and was enforcing springfox runtime. Removing docs profile helped. However if you wanted to use swagger docs using 2.7 feature then try using openapi lib.

arjun kumar
  • 467
  • 5
  • 12
0
implementation 'org.springdoc:springdoc-openapi-ui:1.6.15'
implementation 'io.springfox:springfox-swagger2:3.0.0'
implementation 'io.springfox:springfox-swagger-ui:3.0.0'

https://localhost:8080/swagger-ui/index.html

0

Setting the spring.mvc.pathmatch.matching-strategy = ANT_PATH_MATCHER in the application.properties will hide just hide the javanull error which results in the White label error page.
Use the following solution mentioned in the link
https://stackoverflow.com/a/76671291/17410605

Nati
  • 51
  • 3
-1

Downgrading the Springboot version from 2.6.0 to 2.5.4 solves the issue, provided the below swagger version

    <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>
Himanshu Gupta
  • 189
  • 2
  • 5