Skip to content

Instantly share code, notes, and snippets.

@ericbottard
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ericbottard/ad6da5559257fbcb0325 to your computer and use it in GitHub Desktop.
Save ericbottard/ad6da5559257fbcb0325 to your computer and use it in GitHub Desktop.
This shows leakage of Class<T> by AbstractApplicationEventMulticaster
/**
*
* @author ebottard
*/
public class Foo {
public static void main(String[] args) throws IOException {
AnnotationConfigApplicationContext parent = new AnnotationConfigApplicationContext();
parent.register(Parent.class);
AnnotationConfigApplicationContext child = new AnnotationConfigApplicationContext();
child.register(Child.class);
// child.setParent(parent);
parent.refresh();
child.refresh();
child.publishEvent(new MyEvent(child));
child.close();
child = null;
System.in.read();
}
public static class MyEvent extends ApplicationEvent {
/**
* @param source
*/
public MyEvent(Object source) {
super(source);
// TODO Auto-generated constructor stub
}
}
@Configuration()
public static class Parent {
}
@Configuration()
public static class Child {
@Bean
public ApplicationListener<MyEvent> foo() {
return new ApplicationListener<Foo.MyEvent>() {
@Override
public void onApplicationEvent(MyEvent event) {
System.out.println(event);
}
};
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment