'Error creating bean with name and Singleton bean creation not allowed
I am getting the following exception when I execute the code via JUnit Test Case
org.springframework.beans.factory.BeanCreationNotAllowedException: Error creating bean with name 'somarFactory': Singleton bean creation not allowed while the singletons of this factory are in destruction (Do not request a bean from a BeanFactory in a destroy method implementation!)
Could someone advise what might be the issues?
Solution 1:[1]
Check if you have more than one tomcat's instance.
if this is your case, shutdown all instance then open one and only one instance.
I hope that will help you
Solution 2:[2]
In my case ,
I'm using multiple threads to call beans methods
and before finishing all threads
calling context.close()
made and throws this exception
with removing context.close
my problem solved.
hope useful
Solution 3:[3]
I was having this error while debugging an application on my integration test, trying to call a find method from Spring Data Repository.
My test code was using @Async and @Scheduled. After some research, I disabled these two features on my spring integration test and the problem was resolved.
Solution 4:[4]
@Transactional resolved in my case after using this it resolved transaction conflict between multiple transaction.
@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
I am using Spring Boot + Spring Data
Solution 5:[5]
You can also get this exception if you have a dependency that's in provided scope but it's not available at run time.
Solution 6:[6]
In my case I had:
<dependency>
<groupId>org.springframework.boot</groupId>-->
<artifactId>spring-boot-starter-tomcat</artifactId>-->
<scope>provided</scope>-->
</dependency>
in my pom.xml in a new project. I removed it and now it works.
Solution 7:[7]
I had this error also, but in my case I find out at the end of the error message, that was something related to two endpoints having the same @requestmapping value, I hope it helps :)
Solution 8:[8]
I was getting that error when tests were finished before the moment of finishing the async thread ran at the tested method.
The fix was to ensure, that tests won't finish until the thread job will be done.
Solution 9:[9]
I have really no idea what is going on ! I'm running a project remotely through VScode on an Ubuntu server. Everything worked normally until I got this error without touching it.
What I did is close the remote VScode and connect it again. Boom! it's working again!
I know it might not help to answer this question. Just want to share my weird experience on this error by myself if someone come and see this.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
