'Invalid mapping pattern detected: /**/swagger-ui/**
I am using springdoc-openapi-ui for spring boot API documentation and facing the following issue -
I have added all the necessary configuration as follows -
- The maven dependency -
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.5.2</version>
</dependency>
- This is the main file -
package com.abc.tl;
import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
@OpenAPIDefinition
public class TLApplication {
public static void main(String[] args) {
SpringApplication.run(TLApplication.class, args);
}
}
Using java version - 11, Not sure where is the Issue, the project is not able to run.
Solution 1:[1]
With following dependencies, solved this issue.
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.0</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.5.12</version>
</dependency>
Solution 2:[2]
I added below line in my app application.properties that worked for me.
spring.mvc.pathmatch.matching-strategy = ANT_PATH_MATCHER
Solution 3:[3]
Seems The PathPatternParser doesn't allow ** to appear in the middle, and will reject such a pattern (see more details: https://github.com/spring-projects/spring-boot/issues/21694).
It looks like code here inserted a ** in the middle of the path pattern.
uiRootPath.append(ALL_PATTERN);
registry.addResourceHandler(uiRootPath + SWAGGER_UI_PATTERN)
Full code
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
StringBuilder uiRootPath = new StringBuilder();
if (swaggerPath.contains(DEFAULT_PATH_SEPARATOR))
uiRootPath.append(swaggerPath, 0, swaggerPath.lastIndexOf(DEFAULT_PATH_SEPARATOR));
if (actuatorProvider.isPresent() && actuatorProvider.get().isUseManagementPort())
uiRootPath.append(actuatorProvider.get().getBasePath());
uiRootPath.append(ALL_PATTERN);
registry.addResourceHandler(uiRootPath + SWAGGER_UI_PATTERN)
.addResourceLocations(CLASSPATH_RESOURCE_LOCATION + DEFAULT_WEB_JARS_PREFIX_URL + DEFAULT_PATH_SEPARATOR)
.resourceChain(false)
.addTransformer(swaggerIndexTransformer);
}
Solution 4:[4]
The above item works
spring.mvc.pathpattern.matching-strategy=ant_path_matcher
However, it should be ant-path-matcher - dashes not underscores
Solution 5:[5]
Somewhere in your code (I would guess in the security configuration) you have configured /**/swagger-ui/**. Recently (Spring 5.3) these path configurations are now analyzed by PathPatternParser (that replaced the old AntPathMatcher that allowed paths just like these).
Either add spring.mvc.pathpattern.matching-strategy=ant_path_matcher to your application.properties as suggested or change the your path configuration to something like "/webjars/swagger-ui/**".
Solution 6:[6]
In my case, I was using old versions of springdoc-openapi-ui springdoc-openapi-data-rest, which happened to be incompatible with the latest version of Spring Boot. Looking up for the most recent maven package on https://mvnrepository.com/artifact/org.springdoc/springdoc-openapi-ui and using that version, solved the problem.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Debmalya Jash |
| Solution 2 | Rohit Jakhar |
| Solution 3 | Sachith Wickramaarachchi |
| Solution 4 | user2286976 |
| Solution 5 | João Dias |
| Solution 6 | Haroldo_OK |

