Unable to deploy Spring Boot Application 3.1.5 into Tomcat 10.1.14 with JDK 17.0.8. (Spring Security 6.1.5) I got this error :
2023-11-17T11:47:01.223+02:00 WARN 903 --- [alina-utility-1] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration': Unsatisfied dependency expressed through method 'setFilterChains' parameter 0: Error creating bean with name 'filterChain' defined in class path resource [com/example/project/authentication/config/SecurityConfiguration.class]: Failed to instantiate [org.springframework.security.web.SecurityFilterChain]: Factory method 'filterChain' threw exception with message: This method cannot decide whether these patterns are Spring MVC patterns or not. If this endpoint is a Spring MVC endpoint, please use requestMatchers(MvcRequestMatcher); otherwise, please use requestMatchers(AntPathRequestMatcher).
When I downgraded the Spring Boot Version to 3.1.1 (Spring Security 6.1.1), the deployment done successfully with same code and Security Configuration.
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
final AuthenticationManagerBuilder authenticationManagerBuilder = http.getSharedObject(AuthenticationManagerBuilder.class);
authenticationManagerBuilder.userDetailsService(myUserDetailsService).passwordEncoder(encoder());
final AuthenticationManager authenticationManager = authenticationManagerBuilder.build();
http
.csrf((csrf) -> csrf.disable())
.cors(cors -> withDefaults())
.authorizeHttpRequests((authorizeHttpRequests) ->
authorizeHttpRequests
.requestMatchers("api/v2/dashboard/**").hasRole("USER")
.anyRequest().permitAll()
)
.formLogin(withDefaults())
.authenticationManager(authenticationManager)
.exceptionHandling((exceptionHandling) ->
exceptionHandling
.accessDeniedHandler(jwtAccessDeniedHandler).authenticationEntryPoint(jwtAuthenticationEntryPoint))
.addFilterBefore(jwtFilter, UsernamePasswordAuthenticationFilter.class);
return http.build();
}
Comment From: marcusdacoregio
Hi, @Ugleethyn. Thanks for the report.
This is probably a duplicate of https://github.com/spring-projects/spring-security/issues/13602, please follow the guidance there and from the related issues. If you feel it is not the same problem, please reach back to us and we can reopen this issue.