Я получил эту ошибку при выполнении Spring Secutiry, пожалуйста, помогите мне, мой код
Ошибка при создании bean-компонента с именем 'secutiryConfig': запрошенный bean-компонент в настоящее время находится в стадии создания: есть ли неразрешимый циклический вызов ссылка или зависимость асинхронной инициализации?
package ecourse.secutiry;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.authentication.configurers.userdetails.DaoAuthenticationConfigurer;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.web.SecurityFilterChain;
@Configuration
@EnableWebSecurity
public class SecutiryConfig {
@Bean
public UserDetailsService getUserDetailsServices(){
return new UserDetailsServiceImpl();
}
@Bean
public BCryptPasswordEncoder getPasswordEncoder() {
return new BCryptPasswordEncoder();
}
@Bean
public DaoAuthenticationProvider getDaoAuthenticationProvider() {
DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
provider.setUserDetailsService(getUserDetailsServices());
provider.setPasswordEncoder(getPasswordEncoder());
return provider;
}
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.authenticationProvider(getDaoAuthenticationProvider());
}
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http.authorizeHttpRequests((requests) -> requests
.requestMatchers("/admin/**").hasAuthority("admin") // Chỉ người dùng có quyền "admin" mới được truy cập các URL bắt đầu bằng "/admin/"
.requestMatchers("/user/**").hasAuthority("user") // Chỉ người dùng có quyền "user" mới được truy cập các URL bắt đầu bằng "/user/"
.requestMatchers("/**").permitAll() // Cho phép tất cả mọi người truy cập các URL còn lại
)
.formLogin((form) -> form
.loginPage("/home/signin") // Định nghĩa trang đăng nhập tùy chỉnh tại URL "/home/signin"
.loginProcessingUrl("/login") // URL xử lý đăng nhập
.defaultSuccessUrl("/user/") // URL chuyển hướng sau khi đăng nhập thành công
)
.csrf((csrf) -> csrf.disable()); // Vô hiệu hóa CSRF (Cross-Site Request Forgery)
return http.build();
}
}
Я пытался спросить ChatGPT, но безуспешно.
Я использую Spring Boot 3.4.0
Я получил эту ошибку при выполнении Spring Secutiry, пожалуйста, помогите мне, мой код Ошибка при создании bean-компонента с именем 'secutiryConfig': запрошенный bean-компонент в настоящее время находится в стадии создания: есть ли неразрешимый циклический вызов ссылка или зависимость асинхронной инициализации? [code]package ecourse.secutiry;
@Configuration @EnableWebSecurity public class SecutiryConfig { @Bean public UserDetailsService getUserDetailsServices(){ return new UserDetailsServiceImpl(); } @Bean public BCryptPasswordEncoder getPasswordEncoder() { return new BCryptPasswordEncoder(); } @Bean public DaoAuthenticationProvider getDaoAuthenticationProvider() { DaoAuthenticationProvider provider = new DaoAuthenticationProvider(); provider.setUserDetailsService(getUserDetailsServices()); provider.setPasswordEncoder(getPasswordEncoder()); return provider; } @Autowired public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { auth.authenticationProvider(getDaoAuthenticationProvider()); }
@Bean public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { http.authorizeHttpRequests((requests) -> requests .requestMatchers("/admin/**").hasAuthority("admin") // Chỉ người dùng có quyền "admin" mới được truy cập các URL bắt đầu bằng "/admin/" .requestMatchers("/user/**").hasAuthority("user") // Chỉ người dùng có quyền "user" mới được truy cập các URL bắt đầu bằng "/user/" .requestMatchers("/**").permitAll() // Cho phép tất cả mọi người truy cập các URL còn lại ) .formLogin((form) -> form .loginPage("/home/signin") // Định nghĩa trang đăng nhập tùy chỉnh tại URL "/home/signin" .loginProcessingUrl("/login") // URL xử lý đăng nhập .defaultSuccessUrl("/user/") // URL chuyển hướng sau khi đăng nhập thành công ) .csrf((csrf) -> csrf.disable()); // Vô hiệu hóa CSRF (Cross-Site Request Forgery) return http.build(); } }
[/code] Я пытался спросить ChatGPT, но безуспешно. Я использую Spring Boot 3.4.0