Skip to content

Break circular references which disabled by default since spring boot 2.6 #1347

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
quaff opened this issue Nov 25, 2021 · 11 comments
Closed
Labels
bug Something isn't working

Comments

@quaff
Copy link

quaff commented Nov 25, 2021


***************************
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.

@thodorispa
Copy link

I have this error too. I put in application.properties :
spring.main.allow-circular-references=true
but it didn't work

@quaff
Copy link
Author

quaff commented Nov 26, 2021

I have this error too. I put in application.properties : spring.main.allow-circular-references=true but it didn't work

spring.main.allow-circular-references: true works for me.

@abdimajidov
Copy link

abdimajidov commented Nov 26, 2021

worked on me too

spring.main.allow-circular-references: true

@bnasslahsen
Copy link
Collaborator

Guys, would be great if you provide a minimal reproducible sample or directly propose a PR.
We will release by the EOM and would be great to prevent this issue without the additionnal property.

@abdimajidov
Copy link

putting @lazy on the constructor is also a good option

@bnasslahsen
Copy link
Collaborator

bnasslahsen commented Nov 28, 2021

This ticket will be closed, as no one has provided a Minimal, Reproducible Example - with HelloController.
It can be reopened, if the relevant information is provided.

@quaff
Copy link
Author

quaff commented Nov 29, 2021

SpringDocWebMvcConfiguration

Do you have customized RequestMappingHandlerMapping like this?

@Component
public class DefaultWebMvcRegistrations implements WebMvcRegistrations {

	@Override
	public RequestMappingHandlerMapping getRequestMappingHandlerMapping() {
		return new MyRequestMappingHandlerMapping();
	}

}

@thodorispa @abdimajidov

@quaff
Copy link
Author

quaff commented Nov 29, 2021

@bnasslahsen Here is example.zip
In customized DefaultRequestMappingHandlerMapping

	@Override
	protected void detectHandlerMethods(Object handler) {
		Object handlerObject = (handler instanceof String ? obtainApplicationContext().getBean((String) handler)
				: handler); // getBean will cause circular references
		handlerHolder.set(handlerObject);
		super.detectHandlerMethods(handler);
		handlerHolder.remove();
	}

@bnasslahsen
Copy link
Collaborator

@quaff,

Thank you for providing a reproducible sample.
This should be now fixed with the latest SNAPSHOT.
You can give it a try and let us know.

@quaff
Copy link
Author

quaff commented Nov 30, 2021

@quaff,

Thank you for providing a reproducible sample. This should be now fixed with the latest SNAPSHOT. You can give it a try and let us know.

It works now, thanks.

@KahugiaEriq
Copy link

I placed the spring.main.allow-circular-references: true and it worked for me too.

@bnasslahsen bnasslahsen added the bug Something isn't working label Jan 10, 2022
@springdoc springdoc deleted a comment from hadiRoudsariW Mar 3, 2022
@springdoc springdoc locked as resolved and limited conversation to collaborators Mar 3, 2022
mpleine pushed a commit to mpleine/springdoc-openapi that referenced this issue May 17, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants