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:
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:
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);
}