You have like this error

org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'configurazioneSpringSecurity': Requested bean is currently in creation: Is there an unresolvable circular reference?

and sure also you have like this message :

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

Description:

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

┌─────┐
|  requestMappingHandlerMapping defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]
↑     ↓
|  openApiResource defined in class path resource [org/springdoc/webmvc/core/SpringDocWebMvcConfiguration.class]
└─────┘


Action:

Relying upon circular references is discouraged and they are prohibited by default. Update your application to remove the dependency cycle between beans. As a last resort, it may be possible to break the cycle automatically by setting spring.main.allow-circular-references to true.

this happen when you autowire the same service in classA and in classB and the classA uses classB

(just an example of many cases to reproduce)

to fix this error you have two choices:

1- try to manage dependencies to avoid this cycle like create separate services to reduce coupling (some coding work and it depends on your case)

2- the simple solution (also for old projects) is to add this parameter in your application.properties file

spring.main.allow-circular-references=true

explanation

Since Spring Boot 2.6, circular dependencies are prohibited by default. you can allow circular references again by setting spring.main.allow-circular-references to true

this is a caption from the official documentation :

Circular References Prohibited by Default
Circular references between beans are now prohibited by default. If your application fails to start due to a BeanCurrentlyInCreationException you are strongly encouraged to update your configuration to break the dependency cycle. If you are unable to do so, circular references can be allowed again by setting spring.main.allow-circular-references to true, or using the new setter methods on SpringApplication and SpringApplicationBuilder This will restore 2.5’s behaviour and automatically attempt to break the dependency cycle.

source

Thank you

Aller au contenu principal