Note: What i'm trying to achieve is to know why spring boot asking to specify mvcMatcher or antMatcher.
Spring boot security SecurityFilterChain config not accepting requestMatchers with string value, and showing below exception on startup:
.class]: Failed to instantiate [org.springframework.security.web.SecurityFilterChain]: Factory method 'configure' 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).
below is Bean code:
`
@Bean
public SecurityFilterChain configure(HttpSecurity httpSecurity) throws Exception {
httpSecurity.csrf(AbstractHttpConfigurer::disable)
.formLogin(AbstractHttpConfigurer::disable)
.authorizeHttpRequests(request ->
request.requestMatchers(("/public/**")).permitAll()
.requestMatchers(("/api/v1/admin/**")).hasAnyRole("ADMIN")
.anyRequest().authenticated());
return httpSecurity.build();
}
`
It worked when I used MvcRequestMatcher but why is failing without it.
Note: I'm using H2 DB for unit test and DB2 for the application.