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]
Comment From: ryanjbaxter
Which app are you shutting down to see this error?
Comment From: timtebeek
@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?
Comment From: brenuart
See https://github.com/spring-cloud/spring-cloud-netflix/issues/2099 for potential hints (same message and an easy way to reproduce)
Comment From: ryanjbaxter
Closing in favor of #2099
Comment From: brenuart
Sorry but this issue is not a duplicate of https://github.com/spring-cloud/spring-cloud-netflix/issues/2099. I referenced it just because one of the modifications proposed in the issue triggers the issue.
In short, the BeanCreationNotAllowedException is thrown by com.netflix.discovery.DiscoveryClient#shutdown() when it attempts to unregister the StatusChangeListener from the ApplicationInfoManager at the following line:
@PreDestroy
@Override
public synchronized void shutdown() {
if (isShutdown.compareAndSet(false, true)) {
logger.info("Shutting down DiscoveryClient ...");
if (statusChangeListener != null && applicationInfoManager != null) {
--> applicationInfoManager.unregisterStatusChangeListener(statusChangeListener.getId());
}
Is it because of the @RefreshScope ?
Comment From: ryanjbaxter
I'm not sure I have not looked into it
Comment From: ryanjbaxter
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.
Comment From: liangAhh
This error occurs with an application that uses spring session to connect to redis
Comment From: bijukunjummen
I also got the same exception on a Zuul based project, but looks like this is an expected behavior - I see this comment on NamedContextFactory - https://github.com/spring-cloud/spring-cloud-commons/blob/master/spring-cloud-context/src/main/java/org/springframework/cloud/context/named/NamedContextFactory.java#L74-L76
Comment From: crmky
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:
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.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1078) [spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.context.event.ApplicationListenerMethodAdapter.getTargetBean(ApplicationListenerMethodAdapter.java:283) ~[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.context.event.ApplicationListenerMethodAdapter.doInvoke(ApplicationListenerMethodAdapter.java:253) ~[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.context.event.ApplicationListenerMethodAdapter.processEvent(ApplicationListenerMethodAdapter.java:177) ~[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.context.event.ApplicationListenerMethodAdapter.onApplicationEvent(ApplicationListenerMethodAdapter.java:140) ~[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:167) ~[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) ~[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:393) [spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:399) [spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:347) [spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:991) [spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:958) [spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.cloud.context.named.NamedContextFactory.destroy(NamedContextFactory.java:76) [spring-cloud-context-1.2.3.RELEASE.jar:1.2.3.RELEASE]
at org.springframework.beans.factory.support.DisposableBeanAdapter.destroy(DisposableBeanAdapter.java:272) [spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroyBean(DefaultSingletonBeanRegistry.java:578) [spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingleton(DefaultSingletonBeanRegistry.java:554) [spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingleton(DefaultListableBeanFactory.java:961) [spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingletons(DefaultSingletonBeanRegistry.java:523) [spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.destroySingletons(FactoryBeanRegistrySupport.java:230) [spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingletons(DefaultListableBeanFactory.java:968) [spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:1030) [spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1006) [spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:958) [spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.boot.actuate.endpoint.ShutdownEndpoint$1.run(ShutdownEndpoint.java:74) [spring-boot-actuator-1.5.6.RELEASE.jar:1.5.6.RELEASE]
at java.lang.Thread.run(Thread.java:748) [na:1.8.0_131]
The root cause is when closing ApplicationContext, it will destroy all singleton bean, eurekaAutoServiceRegistration is destroyed first, then feignContext. When destroy feignContext, it will close the ApplicationContext associated with each FeignClient. Since eurekaAutoServiceRegistration listen on ContextClosedEvent, those events will be sent to that bean. Unfortunately because it has been destroyed, so we got the above exception (try to create bean in destruction).
@EventListener(ContextClosedEvent.class)
public void onApplicationEvent(ContextClosedEvent event) {
// register in case meta data changed
stop();
}
I don't have workaround for that. :-(
Comment From: crmky
Found a workaround. Also added more details about the root cause.
When ApplicationContext shutdown, it will destroy all disposable beans (and beans depend on them). In this case:
- FeignContext implements DisposableBean interface
- InetUtils implements AutoCloseable interface
- EurekaServiceRegistry has a public close method
So they are all considered as disposable beans. Since EurekaAutoServiceRegistration depends on InetUtils and EurekaServiceRegistry beans, so if either bean is destroyed, EurekaAutoServiceRegistration will be destroyed.
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 FeignContext usually get instituted before InetUtils and EurekaServiceRegistry, so it will be destroyed after them:
- InetUtils or EurekaServiceRegistry to be destroyed.
- Destroy EurekaAutoServiceRegistration first.
- Destroy InetUtils and EurekaServiceRegistry.
- Destroy FeignContext which will shutdown all ApplicationContext associated with FeignClients.
- EurekaAutoServiceRegistration listen on ContextClosedEvent but it has been destroyed. ApplicationContext will try to create it again, got exception.
Workaround
Make sure InetUtils and EurekaServiceRegistry are instituted before FeignContext. So the sequence become:
- Destroy FeignContext which will shutdown all ApplicationContext associated with FeignClients.
- EurekaAutoServiceRegistration listen on ContextClosedEvent and processed those events.
- InetUtils or EurekaServiceRegistry to be destroyed.
- Destroy EurekaAutoServiceRegistration first.
- Destroy InetUtils and EurekaServiceRegistry.
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 EurekaAutoServiceRegistration.onApplicationEvent and FeignContext.destroy.
Comment From: spencergibb
@crmky 8ad15399d65d35ff1559f5e2e7c153909275185d should fix the
EurekaAutoServiceRegistration listen on ContextClosedEvent and processed those events.
problem. Can you try snapshots?
Adding artificial dependencies isn't the right way to fix things, so we won't be implementing your recommendation.
Comment From: crmky
@spencergibb I tried the latest snapshot version, still see the same stack trace without my workaround.
I think fix within onApplicationEvent method will not work. The problem is EurekaAutoServiceRegistration bean had been destroyed, then it received ContextClosedEvent for the ApplicationContext associated with FeignClients. BeanFactory try to create that bean again and triggered that exception.
Here are the whole steps:
- SpringApplication level ApplicationContext shutdown
- EurekaAutoServiceRegistration.onApplicationEvent get called and deregister Eureka instance.
- EurekaAutoServiceRegistration bean is destroyed. (Because InetUtils and EurekaServiceRegistry are destroyed)
- Destroying FeignContext.
- FeignContext will destroy ApplicationContext associated with each FeignClient.
- ApplicationContext try to notify EurekaAutoServiceRegistration.onApplicationEvent, because of EventListener annotation. But that bean is destroyed, so it try to re-create it.
- Not the right time to create bean (shutdown), exception thrown.
Comment From: Succy
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!
Comment From: fengymi
我在junit里面加了@SpringBootTest(SpringBootTest.WebEnvironment.RANDOM_PORT)就可以调用了
Comment From: itliusir
@fengymi 你这个注解放类上 编译就报错了呀
Comment From: jizhubing
好像没得到解决
Comment From: crmky
With Spring Cloud Edgware, the previous workaround doesn't work anymore. The right workaround should be:
@Component
public class FeignBeanFactoryPostProcessor implements BeanFactoryPostProcessor {
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
if (containsBeanDefinition(beanFactory, "feignContext", "eurekaAutoServiceRegistration")) {
BeanDefinition bd = beanFactory.getBeanDefinition("feignContext");
bd.setDependsOn("eurekaAutoServiceRegistration");
}
}
private boolean containsBeanDefinition(ConfigurableListableBeanFactory beanFactory, String... beans) {
return Arrays.stream(beans).allMatch(b -> beanFactory.containsBeanDefinition(b));
}
}
Comment From: zhangxiangfeng
@crmky I'll give it a try,wait for my news
Comment From: fengymi
@itliusir 报错不会吧,不过这个不是一个好的解决方法。
Comment From: crmky
@spencergibb This problem is still reproducible in Spring Cloud Edgware.SR1. Here is the minimal code to reproduce it:
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent </artifactId>
<version>1.5.10.RELEASE</version>
</parent>
<artifactId>test</artifactId>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Edgware.SR1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
</dependencies>
</project>
Application.java
@SpringBootApplication
@EnableFeignClients
public class Application {
@FeignClient("test")
public static interface TestClient {
}
@Service
public static class TestSerivce {
@Autowired
private TestClient testClient;
}
public static void main(String[] args) throws Exception {
SpringApplication.run(Application.class, args);
}
}
The stack trace is:
2018-02-06 09:53:47.537 INFO 31972 --- [on(2)-127.0.0.1] inMXBeanRegistrar$SpringApplicationAdmin : Application shutdown requested.
2018-02-06 09:53:47.537 INFO 31972 --- [on(2)-127.0.0.1] ationConfigEmbeddedWebApplicationContext : Closing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@5023bb8b: startup date [Tue Feb 06 09:53:41 UTC 2018]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@3d34d211
2018-02-06 09:53:47.538 INFO 31972 --- [on(2)-127.0.0.1] o.s.c.n.e.s.EurekaServiceRegistry : Unregistering application unknown with eureka with status DOWN
2018-02-06 09:53:47.539 INFO 31972 --- [on(2)-127.0.0.1] o.s.c.support.DefaultLifecycleProcessor : Stopping beans in phase 0
2018-02-06 09:53:47.541 INFO 31972 --- [on(2)-127.0.0.1] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown
2018-02-06 09:53:47.542 INFO 31972 --- [on(2)-127.0.0.1] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans
2018-02-06 09:53:47.543 INFO 31972 --- [on(2)-127.0.0.1] com.netflix.discovery.DiscoveryClient : Shutting down DiscoveryClient ...
2018-02-06 09:53:47.543 INFO 31972 --- [on(2)-127.0.0.1] com.netflix.discovery.DiscoveryClient : Completed shut down of DiscoveryClient
2018-02-06 09:53:47.547 INFO 31972 --- [on(2)-127.0.0.1] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@77ee25f1: startup date [Tue Feb 06 09:53:43 UTC 2018]; parent: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@5023bb8b
2018-02-06 09:53:47.557 WARN 31972 --- [on(2)-127.0.0.1] s.c.a.AnnotationConfigApplicationContext : Exception thrown from ApplicationListener handling ContextClosedEvent
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.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1080) [spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.context.event.ApplicationListenerMethodAdapter.getTargetBean(ApplicationListenerMethodAdapter.java:283) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.context.event.ApplicationListenerMethodAdapter.doInvoke(ApplicationListenerMethodAdapter.java:253) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.context.event.ApplicationListenerMethodAdapter.processEvent(ApplicationListenerMethodAdapter.java:177) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.context.event.ApplicationListenerMethodAdapter.onApplicationEvent(ApplicationListenerMethodAdapter.java:140) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:393) [spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:399) [spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:347) [spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:991) [spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:958) [spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.cloud.context.named.NamedContextFactory.destroy(NamedContextFactory.java:76) [spring-cloud-context-1.3.1.RELEASE.jar:1.3.1.RELEASE]
at org.springframework.beans.factory.support.DisposableBeanAdapter.destroy(DisposableBeanAdapter.java:272) [spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroyBean(DefaultSingletonBeanRegistry.java:578) [spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingleton(DefaultSingletonBeanRegistry.java:554) [spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingleton(DefaultListableBeanFactory.java:961) [spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingletons(DefaultSingletonBeanRegistry.java:523) [spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.destroySingletons(FactoryBeanRegistrySupport.java:230) [spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingletons(DefaultListableBeanFactory.java:968) [spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:1032) [spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1008) [spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:958) [spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.boot.admin.SpringApplicationAdminMXBeanRegistrar$SpringApplicationAdmin.shutdown(SpringApplicationAdminMXBeanRegistrar.java:126) [spring-boot-1.5.10.RELEASE.jar:1.5.10.RELEASE]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_151]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_151]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_151]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_151]
at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:71) [na:1.8.0_151]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_151]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_151]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_151]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_151]
at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275) [na:1.8.0_151]
at com.sun.jmx.mbeanserver.ConvertingMethod.invokeWithOpenReturn(ConvertingMethod.java:193) [na:1.8.0_151]
at com.sun.jmx.mbeanserver.ConvertingMethod.invokeWithOpenReturn(ConvertingMethod.java:175) [na:1.8.0_151]
at com.sun.jmx.mbeanserver.MXBeanIntrospector.invokeM2(MXBeanIntrospector.java:117) [na:1.8.0_151]
at com.sun.jmx.mbeanserver.MXBeanIntrospector.invokeM2(MXBeanIntrospector.java:54) [na:1.8.0_151]
at com.sun.jmx.mbeanserver.MBeanIntrospector.invokeM(MBeanIntrospector.java:237) [na:1.8.0_151]
at com.sun.jmx.mbeanserver.PerInterface.invoke(PerInterface.java:138) [na:1.8.0_151]
at com.sun.jmx.mbeanserver.MBeanSupport.invoke(MBeanSupport.java:252) [na:1.8.0_151]
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819) [na:1.8.0_151]
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801) [na:1.8.0_151]
at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1468) [na:1.8.0_151]
at javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:76) [na:1.8.0_151]
at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1309) [na:1.8.0_151]
at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1401) [na:1.8.0_151]
at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:829) [na:1.8.0_151]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_151]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_151]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_151]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_151]
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:357) [na:1.8.0_151]
at sun.rmi.transport.Transport$1.run(Transport.java:200) [na:1.8.0_151]
at sun.rmi.transport.Transport$1.run(Transport.java:197) [na:1.8.0_151]
at java.security.AccessController.doPrivileged(Native Method) [na:1.8.0_151]
at sun.rmi.transport.Transport.serviceCall(Transport.java:196) [na:1.8.0_151]
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568) [na:1.8.0_151]
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826) [na:1.8.0_151]
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:683) [na:1.8.0_151]
at java.security.AccessController.doPrivileged(Native Method) [na:1.8.0_151]
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682) [na:1.8.0_151]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) ~[na:1.8.0_151]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) ~[na:1.8.0_151]
at java.lang.Thread.run(Thread.java:748) ~[na:1.8.0_151]
2018-02-06 09:53:47.562 INFO 31972 --- [on(2)-127.0.0.1] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
Comment From: itliusir
@crmky nice
Comment From: jet55
For me, the same exception occured after tests because of
@Autowired
SpringClientFactory clientFactory;
Solutinon from @crmky helped, with "springClientFactory" bean instead of "feignContext". I'm using Edgware.SR2
Comment From: rafaelrenanpacheco
@crmky workaround + @jet55 suggestion still works on Finchley.M9 :+1:
Edit: The workaround works when running the application, but not when running tests :disappointed:
Comment From: zhujunjie115197
Finchley.M9版本 我报这个错 是因为缺少spring-boot-starter-web依赖,添加之后就不报错了
Comment From: 247292980
@zhujunjie115197 it‘s not work
Comment From: 247292980
@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.
Comment From: dchack
I use Edgware.SR3 have this exception. by crmky's workaround, it don't throw a exception when shutdown my project. And i can't find other way to fix it.so sad.
Comment From: YEMEAC
using ribbon having the same issue cant fix this, the workarounds here are for eureka only
Comment From: laznrbfe
My Java's version is 10.0.1
$ java --version
java 10.0.1 2018-04-17
Console shows me other messages, likes:
java.lang.TypeNotPresentException: Type javax.xml.bind.JAXBContext not present
// ... some messages
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.JAXBContext
I solved ClassNotFoundException and this issues.
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.
Comment From: wulei19922
create project from "spring.io"
These errors occurred when I first ran
Comment From: pobc
@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>
Comment From: Xlinlin
@crmky It's ok, for Spring-Cloud Edgware.SR4!
Comment From: qixiangmei
Despite using the method by @crmky ,I solved the problem,but I still don't know why!!!
Comment From: EeeMt
@crmky works for me, spring boot 1.5.9.RELEASE, spring cloud Dalston.SR5
Comment From: MRStruggle
Finchley.M9版本 我报这个错 是因为缺少spring-boot-starter-web依赖,添加之后就不报错了
感谢 提示,我的是 Finchley.SR1 添加 spring-boot-starter-web依赖 后问题得到解决
Comment From: Gzure
why doesn't remove eurekaAutoServiceRegistration listener from listeners when eurekaAutoServiceRegistration bean destory?
Comment From: crmky
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 https://github.com/spring-cloud/spring-cloud-netflix/commit/12583fd0c25638f95c14973d921ca28cdcd17df5.
Basically @EventListener is not handled properly on shutdown, but ApplicationListener interface is.
@spencergibb I think you can close this issue.
Comment From: qixiangmei
Problem description (I need your help):
我创建了2个微服务,一个微服务叫question(port:8888),一个叫survey(port:8889) , survey 通过feignclient调用question微服务,但通过survey的端口加上question的映射路径依然可以访问到question微服务,为什么
( I created two springboot services, one is question (port: 8888) and the other is survey (port: 8889). Survey calls question springboot service through feignClient, but it can still access question springboot service through the port of survey plus the mapping path of question. Why? )
Attached picture:
Comment From: spencergibb
@qixiangmei please don't ask unrelated questions here. Ask on gitter or stack overflow
Comment From: twfb
@crmky it so helpful to me and it's my code
public class WebappApplication implements BeanFactoryPostProcessor {
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
BeanDefinition bd = beanFactory.getBeanDefinition("feignContext");
bd.setDependsOn("eurekaServiceRegistry", "inetUtils");
}
public static void main(String[] args) {
SpringApplication.run(WebappApplication.class, args);
}
}
then i find error The Tomcat connector configured to listen on port 8002 failed to start. The port may already be in use or the connector may be misconfigured.
so i change my port and success
Comment From: LeiDengDengDeng
@fengymi
It works, and my tests now perform normal! The actual code is @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
Comment From: itersblog
使用这个方案后,这个问题已经解决了,解决Spring Cloud提示BeanCreationNotAllowedException:Error creating bean with name 'eurekaAutoServiceRegistration'的问题
Comment From: xieqiuyu
感谢~~ Edgware.SR1 版本 用这个可以解决 @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
Comment From: GaraYing
With Spring Cloud Edgware, the previous workaround doesn't work anymore. The right workaround should be:
``` @Component public class FeignBeanFactoryPostProcessor implements BeanFactoryPostProcessor {
@Override public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { if (containsBeanDefinition(beanFactory, "feignContext", "eurekaAutoServiceRegistration")) { BeanDefinition bd = beanFactory.getBeanDefinition("feignContext"); bd.setDependsOn("eurekaAutoServiceRegistration"); } } private boolean containsBeanDefinition(ConfigurableListableBeanFactory beanFactory, String... beans) { return Arrays.stream(beans).allMatch(b -> beanFactory.containsBeanDefinition(b)); }} ``` 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: java.lang.IllegalStateException: Shutdown in progress
.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!)
Comment From: startan
@spencergibb This issue hasn't been solved yet. Why is it closed?
Comment From: eugene-sotirescu
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.
Comment From: Kannadasan89
Is there any updates on this issues. I am also facing the same issues and I tried with the workaround as suggested https://github.com/dengly/spring-cloud-study/issues/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. Could you please suggest? Right way to fix it.
Comment From: lnfdxwl
i am also facing the same issyes, 太恶心了