Я использую Spring-boot 2.2.6.RELEASE
, и у меня есть два простых класса:
@Configuration
public class CUserService {
@Autowired
private PasswordEncoder bCryptPasswordEncoder;
@Autowired
public CUserService(PasswordEncoder bCryptPasswordEncoder)
{
this.bCryptPasswordEncoder = bCryptPasswordEncoder;
}
@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
}
и это:
@Configuration
@EnableWebSecurity
public class CWebSecurityConfiguration extends WebSecurityConfigurerAdapter
{
@Autowired
private PasswordEncoder bCryptPasswordEncoder;
@Autowired
public CWebSecurityConfiguration(PasswordEncoder bCryptPasswordEncoder)
{
this.bCryptPasswordEncoder = bCryptPasswordEncoder;
}
}
Когда я компилирую, я получаю:
Description:
The dependencies of some of the beans in the application context form a cycle:
CUserService defined in file [G:\...\classes\com\example\Spring_Authentification\CUserService.class]
Почему я получаю эту ошибку? Где находится cycle
?!
2 - Если я добавлю эту строку в файл application.properties
:
spring.main.allow-bean-definition-overriding=true
и добавлю @Bean declaration
в два класса (CUserService, CWebSecurityConfiguration)
@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
При компиляции я получаю следующую ошибку:
Error creating bean with name 'passwordEncoder': Requested bean is currently in creation: Is there an unresolvable circular reference?
Кто-нибудь может мне помочь? Спасибо