Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-17456

ApplicationListenerMethodAdapter can't be removed after targetBean destroy

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 5.0.9, 5.0.10, 5.1.1, 5.1.2
    • Fix Version/s: Waiting for Triage
    • Component/s: Core
    • Labels:

      Description

      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{}
      }
      

        Attachments

          Activity

            People

            Assignee:
            juergen.hoeller Juergen Hoeller
            Reporter:
            pramy Pramy
            Last updater:
            Spring Issues Spring Issues
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated:
              Days since last comment:
              3 years, 29 weeks, 6 days ago