我在没有WebSecurityConfigurerAdapter的情况下开始在我的应用程序中编写Web安全性,我在内部使用了springboot3,它在此设置下使用了spring 6。我在以下代码中遇到了类似于Cannot resolve method 'antMatchers' in 'ExpressionInterceptUrlRegistry'的错误
.authorizeRequests()
.antMatchers("/register").permitAll()
.anyRequest().authenticated()
.and()
.httpBasic()
完整方法
@Bean
protected SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http
.cors()
.and()
.csrf()
.disable()
.authorizeRequests()
.antMatchers("/register").permitAll()
.anyRequest().authenticated()
.and()
.httpBasic()
.exceptionHandling().authenticationEntryPoint(jwtAuthenticationEntryPoint)
.and()
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS);
return http.build();
}
1条答案
按热度按时间vnzz0bqm1#
从Sping Boot 3.0.0(或Spring Framework 6)开始,
.antMatchers
forAuthorizationManagerRequestMatcherRegistry
不再可用。请改为使用
.requestMatchers("/register")
(若要进行更多自定义,请使用.requestMatchers(new AntPathRequestMatcher()
)示例:
请参阅有关 “使用授权过滤器授权HttpServletRequests” 的Spring安全文档:
https://docs.spring.io/spring-security
请参阅
AntPathRequestMatcher
的链接:AntPathRequestMatcher