-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Eureka shutdown appear BeanCreationNotAllowedException #1952
Comments
Which app are you shutting down to see this error? |
@ryanjbaxter In my case this error appears when I have a JUnit test that uses Eureka, and the error appears after the last test has run. So in essence: Any test run whether it ends in failure or success ends with a the above Eureka stacktrace. Slightly confusing and makes it harder to debug. Any suggestions? |
See #2099 for potential hints (same message and an easy way to reproduce) |
Closing in favor of #2099 |
Sorry but this issue is not a duplicate of #2099. I referenced it just because one of the modifications proposed in the issue triggers the issue. In short, the
Is it because of the |
I'm not sure I have not looked into it |
I guess I am still not sure how to reproduce this issue. Can someone provide details? @smallGit2017 provided sample apps but I am not clear on which app to shutdown to see the exception. |
This error occurs with an application that uses spring session to connect to redis |
I also got the same exception on a Zuul based project, but looks like this is an expected behavior - I see this comment on |
I'm using Spring Boot 1.5.6 with Spring Cloud Dalston SR2. It's easy to reproduce this issue with at least one FeignClient interface and one Component auto-wire that interface. @FeignClient("test")
public interface TestClient {
}
@Service
public class TestService {
@Autowired
private TestClient client;
}
@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
public class Application {
public static void main(String[] args) throws Exception {
SpringApplication.run(Application.class, args);
}
} The following exception will be shown on shutdown:
The root cause is when closing ApplicationContext, it will destroy all singleton bean, @EventListener(ContextClosedEvent.class)
public void onApplicationEvent(ContextClosedEvent event) {
// register in case meta data changed
stop();
} I don't have workaround for that. :-( |
Found a workaround. Also added more details about the root cause. When
Destroy follow First In, Last Out order. Usually application code will not depends on InetUtils or EurekaServiceRegistry, but they depends on FeignClient interfaces. That means
Workaround Make sure
There are several ways to do that. The recommended solution is implement a BeanFactoryPostProcessor: @Component
public class FeignBeanFactoryPostProcessor implements BeanFactoryPostProcessor {
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
BeanDefinition bd = beanFactory.getBeanDefinition("feignContext");
bd.setDependsOn("eurekaServiceRegistry", "inetUtils");
}
} This workaround will eliminate the exception, but the problem is still there in |
@spencergibb I tried the latest snapshot version, still see the same stack trace without my workaround. I think fix within Here are the whole steps:
|
I have this problem too,when I use the Ubuntu16.04 to run consumer application and shutdown by click IDEA's red button, then throw the ugly exception.but, when I use Windows to do same,no exception thrown! |
我在junit里面加了@SpringBootTest(SpringBootTest.WebEnvironment.RANDOM_PORT)就可以调用了 |
@fengymi 你这个注解放类上 编译就报错了呀 |
好像没得到解决 |
With Spring Cloud Edgware, the previous workaround doesn't work anymore. The right workaround should be:
|
@crmky I'll give it a try,wait for my news |
@itliusir 报错不会吧,不过这个不是一个好的解决方法。 |
@spencergibb This problem is still reproducible in Spring Cloud Edgware.SR1. Here is the minimal code to reproduce it: pom.xml
Application.java
The stack trace is:
|
@crmky nice |
@zhujunjie115197 it‘s not work |
@rafaelrenanpacheco but the issuse description ,this exception is appear in running UserServiceTest.java to test the testAddUser() Interface. Until now we don,t do anything on this problem. |
I use Edgware.SR3 have this exception. |
using ribbon having the same issue cant fix this, the workarounds here are for eureka only |
My Java's version is 10.0.1 $ java --version
java 10.0.1 2018-04-17 Console shows me other messages, likes:
I solved You can add the JAX-B APIs as a maven dependency like this: <dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-core</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
</dependency> I hope this will help you. |
@zhujunjie115197 It's work to me, just add follow dependency in maven . <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency> |
@crmky It's ok, for Spring-Cloud Edgware.SR4! |
Despite using the method by @crmky ,I solved the problem,but I still don't know why!!! |
@crmky works for me, spring boot 1.5.9.RELEASE, spring cloud Dalston.SR5 |
感谢 提示,我的是 Finchley.SR1 添加 spring-boot-starter-web依赖 后问题得到解决 |
why doesn't remove eurekaAutoServiceRegistration listener from listeners when eurekaAutoServiceRegistration bean destory? |
Since I have a workaround, I didn't pay much attention to this issue anymore. Today I found this issue has been fixed in Greenwich.M1 by 12583fd. Basically @spencergibb I think you can close this issue. |
Problem description (I need your help):
Attached picture: |
@qixiangmei please don't ask unrelated questions here. Ask on gitter or stack overflow |
@crmky
then i find error |
It works, and my tests now perform normal! The actual code is @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) |
感谢~~ Edgware.SR1 版本 用这个可以解决 @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) |
Thanks for you solution first, but I received another similar Exception when I ran Junit Test while using method in a FeignClient. the console output printed above: .s.c.a.CommonAnnotationBeanPostProcessor : Invocation of destroy method failed on bean with name 'scopedTarget.eurekaClient': org.springframework.beans.factory.BeanCreationNotAllowedException: Error creating bean with name 'eurekaInstanceConfigBean': Singleton bean creation not allowed while singletons of this factory are in destruction (Do not request a bean from a BeanFactory in a destroy method implementation!) |
@spencergibb This issue hasn't been solved yet. Why is it closed? |
this problem persists. it is annoying enough in a web application, imagine how much more annoying it is in a console application which runs every hour and pollutes the log with this stack trace every time it shuts down. |
Is there any updates on this issues. I am also facing the same issues and I tried with the workaround as suggested dengly/spring-cloud-study#5. and its seems like it is working.(i.e) I am not getting the exception. But its seems like multiple times ContextClosedEvent is called/triggered. |
i am also facing the same issyes, 太恶心了 |
I create two service use cloud.
First, run EurekaServerApp.java.
Second, run WorkApp.java.
Third, run UserApp.java.
Finally, run UserServiceTest.java to test the testAddUser() Interface. The data success insert to db, but shutdown I received this ugly exception:
the demo url is https://github.com/smallGit2017/test-0317.git
org.springframework.beans.factory.BeanCreationNotAllowedException: Error creating bean with name 'eurekaAutoServiceRegistration': Singleton bean creation not allowed while singletons of this factory are in destruction (Do not request a bean from a BeanFactory in a destroy method implementation!) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:216) [spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE] at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1081) [spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE] at org.springframework.context.event.ApplicationListenerMethodAdapter.getTargetBean(ApplicationListenerMethodAdapter.java:280) ~[spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE] at org.springframework.context.event.ApplicationListenerMethodAdapter.doInvoke(ApplicationListenerMethodAdapter.java:250) ~[spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE] at org.springframework.context.event.ApplicationListenerMethodAdapter.processEvent(ApplicationListenerMethodAdapter.java:174) ~[spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE] at org.springframework.context.event.ApplicationListenerMethodAdapter.onApplicationEvent(ApplicationListenerMethodAdapter.java:137) ~[spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE] at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:167) ~[spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE] at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) ~[spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE] at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:383) [spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE] at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:389) [spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE] at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:337) [spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE] at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:994) [spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE] at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:961) [spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE] at org.springframework.cloud.context.named.NamedContextFactory.destroy(NamedContextFactory.java:76) [spring-cloud-context-1.2.0.RELEASE.jar:1.2.0.RELEASE] at org.springframework.beans.factory.support.DisposableBeanAdapter.destroy(DisposableBeanAdapter.java:272) [spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroyBean(DefaultSingletonBeanRegistry.java:578) [spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingleton(DefaultSingletonBeanRegistry.java:554) [spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE] at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingleton(DefaultListableBeanFactory.java:961) [spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingletons(DefaultSingletonBeanRegistry.java:523) [spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE] at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingletons(DefaultListableBeanFactory.java:968) [spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE] at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:1033) [spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE] at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1009) [spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE] at org.springframework.context.support.AbstractApplicationContext$2.run(AbstractApplicationContext.java:928) [spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE]
The text was updated successfully, but these errors were encountered: