Skip to content
Advertisement

Application Failed to start The Dependencies of some of the Beans form a cycle… Why?

so I have this section of code in AppConfig.java:

JavaScript

if I get rid of the @Lazy it will not start, i have tried to get rid of the constructor and do:

JavaScript

same thing, can someone please help me out, I really don’t want to have to use the @Lazy Implementation. here is the error it returns:

JavaScript

When getting rid of the constructor and using field injection it gives me this error:

JavaScript

Advertisement

Answer

This error occurs because you’re creating the PasswordEncoder in the same class that you’re injecting it.

The best solution is to not autowire the PasswordEncoder (or the CurrentUserService) at all.

It appears those instances are only used in the configure(AuthenticationManagerBuilder auth) method, which is redundant.

Registering a PasswordEncoder and UserDetailsService as a bean is enough for Spring Security to detect them and use them in your configuration.

In other words, you should remove the following code:

JavaScript

The application will still behave in the exact same way.

Advertisement