Skip to content
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

Closed
smallGit2017 opened this issue May 16, 2017 · 49 comments
Closed

Eureka shutdown appear BeanCreationNotAllowedException #1952

smallGit2017 opened this issue May 16, 2017 · 49 comments

Comments

@smallGit2017
Copy link

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]

@ryanjbaxter
Copy link
Contributor

Which app are you shutting down to see this error?

@timtebeek
Copy link

@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?

@brenuart
Copy link
Contributor

brenuart commented Jul 6, 2017

See #2099 for potential hints (same message and an easy way to reproduce)

@ryanjbaxter
Copy link
Contributor

Closing in favor of #2099

@brenuart
Copy link
Contributor

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 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 ?

@ryanjbaxter
Copy link
Contributor

I'm not sure I have not looked into it

@ryanjbaxter ryanjbaxter reopened this Jul 11, 2017
@ryanjbaxter
Copy link
Contributor

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.

@liangAhh
Copy link

This error occurs with an application that uses spring session to connect to redis

@bijukunjummen
Copy link
Contributor

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

@crmky
Copy link

crmky commented Aug 15, 2017

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. :-(

@crmky
Copy link

crmky commented Aug 16, 2017

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.

@spencergibb
Copy link
Member

@crmky 8ad1539 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.

@crmky
Copy link

crmky commented Aug 16, 2017

@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.

@Succy
Copy link

Succy commented Sep 14, 2017

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!

@fengymi
Copy link

fengymi commented Nov 27, 2017

我在junit里面加了@SpringBootTest(SpringBootTest.WebEnvironment.RANDOM_PORT)就可以调用了

@itliusir
Copy link

@fengymi 你这个注解放类上 编译就报错了呀

@jizhubing
Copy link

好像没得到解决

@crmky
Copy link

crmky commented Jan 5, 2018

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));
    }
}

@zhangxiangfeng
Copy link

@crmky I'll give it a try,wait for my news

@fengymi
Copy link

fengymi commented Jan 29, 2018

@itliusir 报错不会吧,不过这个不是一个好的解决方法。

@crmky
Copy link

crmky commented Feb 6, 2018

@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]

@itliusir
Copy link

@crmky nice

@247292980
Copy link

@zhujunjie115197 it‘s not work

@247292980
Copy link

@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.

@dchack
Copy link

dchack commented Jun 8, 2018

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.

@YEMEAC
Copy link

YEMEAC commented Jul 3, 2018

using ribbon having the same issue cant fix this, the workarounds here are for eureka only

@laznrbfe
Copy link

laznrbfe commented Jul 27, 2018

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.

@wulei19922
Copy link

error

create project from "spring.io"
These errors occurred when I first ran

@spring-cloud spring-cloud deleted a comment from rt-works Aug 14, 2018
@pobc
Copy link

pobc commented Aug 23, 2018

@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>

@Xlinlin
Copy link

Xlinlin commented Sep 11, 2018

@crmky It's ok, for Spring-Cloud Edgware.SR4!

@qixiangmei
Copy link

Despite using the method by @crmky ,I solved the problem,but I still don't know why!!!

@EeeMt
Copy link

EeeMt commented Oct 9, 2018

@crmky works for me, spring boot 1.5.9.RELEASE, spring cloud Dalston.SR5

@MRStruggle
Copy link

Finchley.M9版本 我报这个错 是因为缺少spring-boot-starter-web依赖,添加之后就不报错了

感谢 提示,我的是 Finchley.SR1 添加 spring-boot-starter-web依赖 后问题得到解决

@Gzure
Copy link

Gzure commented Nov 6, 2018

why doesn't remove eurekaAutoServiceRegistration listener from listeners when eurekaAutoServiceRegistration bean destory?

@crmky
Copy link

crmky commented Nov 14, 2018

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 @EventListener is not handled properly on shutdown, but ApplicationListener interface is.

@spencergibb I think you can close this issue.

@qixiangmei
Copy link

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:

103
104
105
106
107

@spencergibb
Copy link
Member

@qixiangmei please don't ask unrelated questions here. Ask on gitter or stack overflow

@twfb
Copy link

twfb commented Dec 17, 2018

@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

@LeiDengDengDeng
Copy link

@fengymi

It works, and my tests now perform normal! The actual code is @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)

@itersblog
Copy link

itersblog commented Jan 30, 2019

@xieqiuyu
Copy link

感谢~~ Edgware.SR1 版本 用这个可以解决 @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)

@GaraYing
Copy link

GaraYing commented Jun 7, 2019

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!)

@startan
Copy link

startan commented Jun 16, 2019

@spencergibb This issue hasn't been solved yet. Why is it closed?

@eugene-sotirescu
Copy link

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.

@Kannadasan89
Copy link

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.
Could you please suggest? Right way to fix it.

@lnfdxwl
Copy link

lnfdxwl commented Jan 17, 2020

i am also facing the same issyes, 太恶心了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests