Skip to content
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

SpringBoot 3.4.0 Error creating bean with name 'openApiResource' #2819

Open
fangzhengjin opened this issue Dec 18, 2024 · 1 comment
Open

Comments

@fangzhengjin
Copy link

Describe the bug

SpringBoot: 3.4.0
SpringDoc: 2.7.0

Application cannot be start

To Reproduce

springdoc:
  enable-default-api-docs: true

Additional context

2024-12-18 14:48:45.153 [SW_CTX: N/A] [pool-2-thread-1] INFO  o.s.b.f.s.DefaultListableBeanFactory -Creating singleton bean 'openApiResource' in thread "pool-2-thread-1" while other thread holds singleton lock for other beans [openApiResource]
Exception in thread "pool-2-thread-1" org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'openApiResource': Requested bean is currently in creation: Is there an unresolvable circular reference or an asynchronous initialization dependency?
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.beforeSingletonCreation(DefaultSingletonBeanRegistry.java:420)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:281)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:334)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansWithAnnotation(DefaultListableBeanFactory.java:743)
	at org.springframework.context.support.AbstractApplicationContext.getBeansWithAnnotation(AbstractApplicationContext.java:1440)
	at org.springdoc.core.service.OpenAPIService.build(OpenAPIService.java:269)
	at org.springdoc.api.AbstractOpenApiResource.getOpenApi(AbstractOpenApiResource.java:352)
	at org.springdoc.api.AbstractOpenApiResource.lambda$new$0(AbstractOpenApiResource.java:258)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
	at java.base/java.lang.Thread.run(Thread.java:1583)
@fangzhengjin
Copy link
Author

fangzhengjin commented Dec 18, 2024

Through analysis, the problem should be here https://github.com/springdoc/springdoc-openapi/blob/main/springdoc-openapi-starter-common/src/main/java/org/springdoc/core/service/OpenAPIService.java#L269

  1. context.getBeansWithAnnotation(RestController.class) Need to obtain org.springdoc.webmvc.api.OpenApiWebMvcResource
  2. org.springdoc.webmvc.api.OpenApiWebMvcResource Need to inject OpenAPIService

It is possible that it is related to the loading logic of the new version of Springboot,Add a breakpoint at context.getBeansWithAnnotation(RestController.class), release it after a while, and everything loads normally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant