简体   繁体   中英

Requested bean is currently in creation: Is there an unresolvable circular reference During adding one spring boot applciation to another?

Scenario: I have a springboot applcation which perform a batch like functionality (Reading data from s3 processing and writing to sql tables).

I also have a seperate Jmix application. So in need to add the batch to this jmix application so that i can run the batch from jmix application

I was able to add it in buid.gradle and i done like below in main class of jmix application

@SpringBootApplication(scanBasePackages = {"com.publicismedia.uniquebatchjava"})
@EnableJmixDataRepositories(basePackages = {})
@EnableJpaRepositories(basePackages = {"com.publicismedia.uniquebatchjava.repository"})

So that we can use the beans in the Jmix app( scanBasePackages = {"com.publicismedia.uniquebatchjava"} ) Jmix tries to create bean for all repository class whether it is on main application or dependency application So i am adding this @EnableJmixDataRepositories(basePackages = {}) to avoid jmix to scan nothing and @EnableJpaRepositories(basePackages = {"com.publicismedia.uniquebatchjava.repository"}) to allow jpa to scan dependent application

And the error now is

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'OAuth2AuthorizationServerConfiguration': Unsatisfied dependency expressed through field 'tokenStore'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'sec_TokenStore' defined in class path resource [io/jmix/autoconfigure/securityoauth2/SecurityOAuth2AutoConfiguration$JdbcTokenStoreConfiguration.class]: Unsatisfied dependency expressed through method 'tokenStore' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'stellantisroiApplication': Unsatisfied dependency expressed through field 'batchExecuter'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'batchExecuter': Unsatisfied dependency expressed through field 'batchConfigRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'batchConfigRepository' defined in com.publicismedia.uniquebatchjava.repository.BatchConfigRepository defined in @EnableJpaRepositories declared on StellantisroiApplication: Cannot create inner bean '(inner bean)#51e0629a' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#51e0629a': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'jmix_Liquibase' defined in class path resource [io/jmix/autoconfigure/data/JmixLiquibaseAutoConfiguration.class]: Unsatisfied dependency expressed through method 'liquibase' parameter 0; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'dataSource': Requested bean is currently in creation: Is there an unresolvable circular reference?

Do any one has any solution or simply how to add a spring boot maven app in to other spring boot maven app considering com.package1.* is main app and com.package2.* as dependent application

First of all please fix the title as it says something different that enclosed stacktrace. Please read

Requested bean is currently in creation: Is there an unresolvable circular reference?

It means that you have a bean "A" which depends on another bean "B" but "B" depends on "A" and this is the reason of a circular reference. Of course this cycle can be longer, for example: A -> B -> C -> A . You have to follow good design principles and remove this cycle somehow or you can use @Lazy annotation on a field to initiate a bean later (by default it's eager dependency).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM