Unresolvable circular reference? - spring-boot

Error creating bean with name 'restFilter': Requested bean is currently in creation: Is there an unresolvable circular reference?
Showing while deploying that microservice in jenkins.
and i have use #Lazy and #lazy in restFilter parametrizeed constructor
Can anyone help me to resolve this problem.
I have use #Lazy in one of the class and #lazy in restFilter parametrizeed constructor.

Related

Spring boot version changes to 2.6.6 from 2.3.4.RELEASE

I have changed the spring boot version to 2.6.6 from 2.3.4.RELEASE because of security vulnerabilities. My application's deployment is failing.
In pom.xml I have changed the version of only springboot.
<spring.boot.version>2.6.6</spring.boot.version>
Error Log:
Unsatisfied dependency expressed through field ''; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name '': Unsatisfied dependency expressed through field ''; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name '': Unsatisfied dependency expressed through field ''; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name '': Unsatisfied dependency expressed through field ''; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name '': Unsatisfied dependency expressed through field ''; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name '': Requested bean is currently in creation: Is there an unresolvable circular reference?"
Well the error message states
Requested bean is currently in creation: Is there an unresolvable circular reference?"
Usually spring boot displays the services for which the circularity was detected. I personally had this problem in the past. The dependency injection is not 100% deterministic and some unrelated changes in your project are now ending up in the detection of such an circular dependency. I am guessing that you are using
#Autowired
to inject you dependencies? When using constructor injection such problems are no longer exist Spring #Autowire on Properties vs Constructor
For now you sadly don´t have any other options then to resolve your circular dependency.
If i am wrong here you need to show more of your exception. from what little that we have it is hard to conclude what is going on :)
spring-boot family starting from 2.6.X not allowing circular reference
you can add to your properties this line:
spring.main.allow-circular-references=true
#GJohannes The code is tightly coupled and in many places, I am using #Autowired. Instead of this can I use spring.main.allow-circular-references=true

Requested bean is currently in creation: Is there an unresolvable circular reference Jules cucumber test

Facing one issue related to integration of functional test in Jules Pipeline. When testing on local in IntelliJ, the functional cucumber test scripts are getting passed, but when deploying on jules , getting BeanCurrentlyInCreationException for all beans.
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'authTokenInterceptor': Unsatisfied dependency expressed through field 'entitlementsFeignClient'; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'mvcResourceUrlProvider': Requested bean is currently in creation
Is there an unresolvable circular reference?
Sometimes it passed and sometimes it fails with this exception.

Is there a way to mark a bean as not primary in Spring?

I am having two beans in different packages out of which one of them is a library so cannot edit, and execution gives the
org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type '' available:
For current purpose I want the bean in the library to be the primary bean, is there a way to avoid using the second bean which i can edit , without deleting the bean?
So far have only seen the #Primary annotation
when spring is trying to inject the dependency it found to to beans for it .
so you have add #Qualifier annotation and give the corresponding class in it which you want to inject

Failed to start project sometimes,report an error : unresolvable circular reference

We failed to start project sometimes, of course launched successfully most of the time. Error reported during failure:
[AbstractApplicationContext.java] refresh : 487 -- Exception encountered during context initialization - cancelling refresh attempt
org.springframework.beans.factory.BeanCurrentlyInCreationException:
Error creating bean with name 'ITsysDesktopConfig':
Requested bean is currently in creation:
Is there an unresolvable circular reference?
I am sure there is no circular reference.
Spring version 4.1.1.RELEASE is used, and I use Spring XML file, not annotation in project
When I was using computer with higher configuration,there is less chance of error happening.
The problem could be with
#ComponentScan(basePackages = "com.my.app")
Try to change
#ComponentScan(basePackages = "com.my.app")
to
#ComponentScan(basePackages = {"com.my.app.service", "com.my.app.config", "com.my.app"})
I think this is a Spring issue with beans loader...
Reference:
https://github.com/spring-projects/spring-boot/issues/6045
https://jira.spring.io/browse/SPR-14307
Why does Spring get circular dependency issues on one machine and not another?
https://www.logicbig.com/tutorials/spring-framework/spring-core/circular-dependencies.html

Spring initialization done outside the project

I have a java spring project . I see that one way of initialing the spring project is using this code in the main method.
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(Config.class);
ctx.scan("com.example.db.app");
ctx.refresh();
Is it possible to keep this outside a main method and then make a jar of this project. Add it as a dependency in pom.xml in other project and call the method which initializes the spring artifacts from there.
I tried doing it. I am getting an error.
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'itemInformationRepositoryService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void com.example.db.app.service.ItemInformationRepositoryService.setItemInformationRepositoryService(com.example.db.app.repository.ItemInformationRepository); nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.example.db.app.repository.ItemInformationRepository] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}
The exception message states:
No qualifying bean of type [com.example.db.app.repository.ItemInformationRepository] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency.
This means that the class com.example.db.app.repository.ItemInformationRepository is not in the Spring context. Perhaps you were expecting Spring to discover this class as a result of your instruction to Spring to scan com.example.db.app? According to the Javadocs for AnnotationConfigApplicationContext.scan() ...
Perform a scan within the specified base packages.
#param basePackages the packages to check for annotated classes
So, in order for Spring to discover com.example.db.app.repository.ItemInformationRepository you must either:
Annotate it with org.springframework.stereotype.Component so that it is discovered by scan()
Register it in the same way as you are registering Config.class e.g. ctx.register(ItemInformationRepository.class);

Resources