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

ApplicationListenerMethodAdapter can't be removed after targetBean destroy [SPR-17456] #21988

Open
spring-issuemaster opened this issue Nov 2, 2018 · 0 comments

Comments

@spring-issuemaster
Copy link
Collaborator

@spring-issuemaster spring-issuemaster commented Nov 2, 2018

Pramy opened SPR-17456 and commented

I know a bean implement ApplicationListener will be remove from Context when it destroy,

but ApplicationListenerMethodAdapter can't be remove 


1.ParentContext invoke close method

2.Listener destroy

  it did not implements ApplicationListener when use @EventListener

3.NamedContext destroy

  it will invoke close method and publish close event, and parentContext will also publish close
  event, ApplicationListenerMethodAdapter working will invoke conetext#getBean


@SpringBootApplication
public class DemoApplication {

    public static void main(String[] args) {
        ConfigurableApplicationContext context = SpringApplication.run(DemoApplication.class, args);
        context.close();
    }

    class Listener implements DisposableBean {

        @EventListener(ContextClosedEvent.class)
        public void close(ApplicationEvent event) {
            System.out.println("---------------invoke listener"+event );
        }
        @Override
        public void destroy() throws Exception {
            System.out.println("--------------------listener destroy-----------------------");
        }
    }


    //1.insure NamedContextFactory initialize before listener
    //2.insure NamedContextFactory destroy after listener
    @Bean
    public Listener listener() {
        //3.initialize context values
        namedContextFactory().getInstance("demo",DemoApplication.class);
        return new Listener();
    }

    @Bean
    public NamedContextFactory<NamedContextFactory.Specification> namedContextFactory() {
        return new NamedContextFactory<NamedContextFactory.Specification>(Config.class
        ,"demo","demo") {};
    }

    @Configuration
    class Config{}
}

Affects: 5.0.9, 5.0.10, 5.1.1, 5.1.2

Reference URL: https://github.com/Pramy/spring-listener-bug

Attachments:

Referenced from: pull request #2006

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.