我将项目从 spring boot 3.2.6 更新到3.3.0 出现以下消息:
[WARN ] 2024-06-06 16:15:14.443 [restartedMain] InitializeUserDetailsBeanManagerConfigurer$InitializeUserDetailsManagerConfigurer - Global AuthenticationManager configured with an AuthenticationProvider bean. UserDetailsService beans will not be used for username/password login. Consider removing the AuthenticationProvider bean. Alternatively, consider using the UserDetailsService in a manually instantiated DaoAuthenticationProvider.
配置:
@Configuration
@EnableWebSecurity
@EnableMethodSecurity
@RequiredArgsConstructor
public class SecurityConfiguration {
private final JwtAuthFilter jwtAuthFilter;
private final MyUserDetails myUserDetails;
@Bean
SecurityFilterChain securityFilterChain(final HttpSecurity http) throws Exception {
return http
.cors(AbstractHttpConfigurer::disable)
.csrf(AbstractHttpConfigurer::disable)
.authorizeHttpRequests(
auth -> auth.requestMatchers("/public/**").permitAll()
.requestMatchers("/api/v1/token", "/api/v1/refreshToken").permitAll()
.anyRequest().authenticated()
)
.sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
.addFilterBefore(jwtAuthFilter, UsernamePasswordAuthenticationFilter.class)
.build();
}
@Bean
AuthenticationManager authenticationManager(AuthenticationConfiguration configuration) throws Exception {
return configuration.getAuthenticationManager();
}
@Bean
PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
@Bean
AuthenticationProvider authenticationProvider() {
var provider = new DaoAuthenticationProvider();
provider.setUserDetailsService(myUserDetails);
provider.setPasswordEncoder(passwordEncoder());
return provider;
}
}
我不知道该怎么办
我什至不知道去哪里挖(
根据新版本,
AuthenticationProvider
可以自己拉起来:source解决办法很简单:删除Bean注册的
Bean
方法即可authenticationProvider()