环境配置
- jdk 17
xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.2.5</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
解决办法
java
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http.csrf(AbstractHttpConfigurer::disable);// 关闭 crsf保护
// 设置需要进行权限认证的请求
http.authorizeRequests((authorizeRequests) ->
authorizeRequests
.requestMatchers("/**").hasRole("USER")
).formLogin(withDefaults());
return http.build();
}