I am in the process of migrating Springboot from 2.5 to 3.4 (it sits at 3.0 at the time of recording)
and one thing that changes is that the ant path matcher is no longer the default, therefore i added this to my application.yaml
spring:
mvc:
pathmatch:
matching-strategy: ant_path_matcher
which usually solves the problem which i have done multiple times. but the Error persists.
This is the WebMvcConfig.kt
file:
package our.application.path.configuration
import com.fasterxml.jackson.databind.ObjectMapper
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter
import org.springframework.web.cors.CorsConfiguration
import org.springframework.web.cors.CorsConfigurationSource
import org.springframework.web.cors.UrlBasedCorsConfigurationSource
import org.springframework.web.servlet.config.annotation.EnableWebMvc
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer
@Configuration
@EnableWebMvc
class WebMvcConfig : WebMvcConfigurer {
companion object {
// Forwarding target
const val FORWARD_INDEX_HTML = "forward:/index.html"
}
override fun addViewControllers(registry: ViewControllerRegistry) {
// Map "/" to /index.html
registry.addViewController("/").setViewName(FORWARD_INDEX_HTML)
// Single directory level - no need to exclude "api"
registry.addViewController("/{x:[\\w\\-]+}").setViewName(FORWARD_INDEX_HTML)
// Multi-level directory path, need to exclude "api" on the first part of the path
registry.addViewController("/{x:^(?!api$).*$}/**/{y:[\\w\\-]+}").setViewName(FORWARD_INDEX_HTML)
}
@Bean
fun corsConfigurationSource(): CorsConfigurationSource {
val source = UrlBasedCorsConfigurationSource()
source.registerCorsConfiguration("/**", CorsConfiguration().applyPermitDefaultValues())
return source
}
@Bean
open fun mappingJackson2HttpMessageConverter(objectMapper: ObjectMapper): MappingJackson2HttpMessageConverter {
return MappingJackson2HttpMessageConverter(objectMapper)
}
}
The Error occurs with or without the added fix in the yaml file and occurs at the end of the application start:
2025-05-22 16:56:15.229 INFO 29128 --- [ main] s.w.a.s.ProblemSecurityBeanPostProcessor [] : Register HttpSecurity's exceptionHandling
2025-05-22 16:56:15.289 WARN 29128 --- [ main] ConfigServletWebServerApplicationContext [] : Exception encountered during context initialization - cancelling refresh attempt:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'publicApiFilterChain' defined in class path resource [our/application/path/configuration/SecurityConfig.class]:
Unsatisfied dependency expressed through method 'publicApiFilterChain' parameter 1: Error creating bean with name 'mvc' defined in class path resource
[our/application/path/configuration/SecurityConfig.class]: Unsatisfied dependency expressed through method 'mvc' parameter 0: Error creating bean with name 'mvcHandlerMappingIntrospector' defined in class path resource
[org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfiguration.class]: Error creating bean with name 'viewControllerHandlerMapping' defined in class path resource
[org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfiguration.class]: No more pattern data allowed after {*...} or ** pattern element
2025-05-22 16:56:15.290 INFO 29128 --- [ main] j.LocalContainerEntityManagerFactoryBean [] : Closing JPA EntityManagerFactory for persistence unit 'default'
2025-05-22 16:56:15.291 INFO 29128 --- [ main] com.zaxxer.hikari.HikariDataSource [] : HikariPool-1 - Shutdown initiated...
2025-05-22 16:56:15.304 INFO 29128 --- [ main] com.zaxxer.hikari.HikariDataSource [] : HikariPool-1 - Shutdown completed.
2025-05-22 16:56:15.306 INFO 29128 --- [ main] o.apache.catalina.core.StandardService [] : Stopping service [Tomcat]
2025-05-22 16:56:15.319 INFO 29128 --- [ main] .s.b.a.l.ConditionEvaluationReportLogger [] :
Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled.
2025-05-22 16:56:15.332 ERROR 29128 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter [] :
***************************
APPLICATION FAILED TO START
***************************
Description:
Invalid mapping pattern detected: /{x:^(?!api$).*$}/**/{y:[\w\-]+}
^
No more pattern data allowed after {*...} or ** pattern element
Action:
Fix this pattern in your application or switch to the legacy parser implementation with 'spring.mvc.pathmatch.matching-strategy=ant_path_matcher'.
Process finished with exit code 1
Additional Info: I have:
for further information feel free to ask
All spring.mvc.*
properties are applied by Spring Boot's auto-configuration for Spring MVC. You have annotated your WebMvcConfig
class with @EnableWebMvc
which disables Spring Boot's auto-configuration for Spring MVC. As a result, the spring.mvc.pathmatch.matching-strategy
property is ignored.
You should be able to fix the problem by removing @EnableWebMvc
from WebMvcConfig
. It implements WebMvcConfigurer
so it will still be called to fine-tune Spring MVC's configuration.