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:
-
Reference URL:
-
Last commented by a User:true
-
Pull Request URL:
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{} }