Home > Enterprise >  How could this has cycle dependencies?
How could this has cycle dependencies?

Time:06-08

When launching my java application, I got the following errors:

***************************
APPLICATION FAILED TO START
***************************

Description:

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

┌──->──┐
|  securityConfiguration
└──<-──┘

Although the log is vivid, I still don't understand how SecurityConfiguration has cycle bean dependencies.

Stackoverflow doesn't allow me to easily paste the codes of SecurityConfiguration, so here they are: https://gist.github.com/blackmonkey/615232845025663597a2ba5f711caff5

CodePudding user response:

The problem is the password encoder. It is required to build the auto-configured beans that you are injecting in the contructor of the class.

You can break the cycle by making the bean factory method static:

@Bean
public static PasswordEncoder passwordEncoder() {
  return new BCryptPasswordEncoder();
}

This make it clear to Spring that the encoder does not depend on anything injected into the class instance.

  • Related