RameshMF / registration-login-spring-boot-security-thymeleaf-hibernate

Registration and Login with Spring Boot, Spring Security, Thymeleaf, Hibernate and MySQL
https://youtu.be/Hk70e7KR290
185 stars 147 forks source link

I tried recreating the code but I am getting an error #5

Open vibhanshujha opened 2 years ago

vibhanshujha commented 2 years ago

The dependencies of some of the beans in the application context form a cycle:

┌─────┐ | securityConfiguration (field private com.themechguy.registrationpage.service.UserService com.themechguy.registrationpage.config.SecurityConfiguration.userServices) ↑ ↓ | userServiceImpl (field private org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder com.themechguy.registrationpage.service.UserServiceImpl.passwordEncoder) └─────┘

lawrencematthew19942016 commented 2 years ago

I am also getting this same issue.

vibhanshujha commented 2 years ago

Hi Try removing @Autowired annotation and creating the following code snippet from userServiceImpl. It helps in tackling the circular dependency error. @Lazy-> it initializes it lazily only when called and helps in tackling the issue.

private UserReopsitory userReopsitory;

public UserServiceImpl( @Lazy UserReopsitory userReopsitory) {
    super();
    this.userReopsitory = userReopsitory;
}