I have added spring security to my maven project.
and i want some url to access by any one so i have used the below code
@Configuration
@EnableWebSecurity
public class SecurityConfig {
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http
.csrf().disable()
.authorizeRequests()
.antMathcers("/api/public").permitAll()
.anyRequest().authenticated()
.and()
.formLogin().permitAll()
.and()
.logout().permitAll();
return http.build();
}
}
and i get the following error
The method antMathcers(String)
is undefined for the type ExpressionUrlAuthorizationConfigurer.ExpressionInterceptUrlRegistry
I have searched in chatGPT and it says:
The antMatchers method is still valid in the newer Spring Security configuration. If you’re encountering an error that antMatchers is undefined, it might be due to some other issue, such as incorrect imports or a mismatch in Spring Security versions.
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.web.SecurityFilterChain;
these are my import statements and i have imported them correctly.
is there any other way to public some urls in spring boot