@Override public Object postProcessAfterInitialization(Object bean, String beanName) { if (bean instanceof ApplicationListener) { // potentially not detected as a listener by getBeanNamesForType retrieval Boolean flag = this.singletonNames.get(beanName); if (Boolean.TRUE.equals(flag)) { // singleton bean (top-level or inner): register on the fly this.applicationContext.addApplicationListener((ApplicationListener<?>) bean); } else if (Boolean.FALSE.equals(flag)) { if (logger.isWarnEnabled() && !this.applicationContext.containsBean(beanName)) { // inner bean with other scope - can't reliably process events logger.warn("Inner bean '" + beanName + "' implements ApplicationListener interface " + "but is not reachable for event multicasting by its containing ApplicationContext " + "because it does not have singleton scope. Only top-level listener beans are allowed " + "to be of non-singleton scope."); } this.singletonNames.remove(beanName); } } return bean; }
@Override public Object postProcessAfterInitialization(Object bean, String beanName) { if (bean instanceof ApplicationListener) { // potentially not detected as a listener by getBeanNamesForType retrieval Boolean flag = this.singletonNames.get(beanName); if (Boolean.TRUE.equals(flag)) { // singleton bean (top-level or inner): register on the fly this.applicationContext.addApplicationListener((ApplicationListener<?>) bean); } else if (Boolean.FALSE.equals(flag)) { if (logger.isWarnEnabled() && !this.applicationContext.containsBean(beanName)) { // inner bean with other scope - can't reliably process events logger.warn("Inner bean '" + beanName + "' implements ApplicationListener interface " + "but is not reachable for event multicasting by its containing ApplicationContext " + "because it does not have singleton scope. Only top-level listener beans are allowed " + "to be of non-singleton scope."); } this.singletonNames.remove(beanName); } } return bean; }
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { if (loader.components == null) { WebxComponentsImpl components = loader.createComponents(loader.getParentConfiguration(), beanFactory); AbstractApplicationContext wcc = (AbstractApplicationContext) components.getParentApplicationContext(); wcc.addApplicationListener(new SourceFilteringListener(wcc, components)); loader.components = components; } }
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { if (loader.components == null) { WebxComponentsImpl components = loader.createComponents(loader.getParentConfiguration(), beanFactory); AbstractApplicationContext wcc = (AbstractApplicationContext) components.getParentApplicationContext(); wcc.addApplicationListener(new SourceFilteringListener(wcc, components)); loader.components = components; } }
/** {@inheritDoc} */ public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { if (applicationContext instanceof AbstractApplicationContext) { ctx = (AbstractApplicationContext) applicationContext; ctx.addApplicationListener(this); } }
@Autowired private AbstractApplicationContext context; private void registerListeners() { ProjectsRepositoryListener firstListener = beanFactory.createBean(ProjectsRepositoryListener.class); context.addApplicationListener(firstListener); MySecondListener secondListener = beanFactory.createBean(MySecondListener.class); context.addApplicationListener(secondListener); }
/** {@inheritDoc} */ public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { if (applicationContext instanceof AbstractApplicationContext) { ctx = (AbstractApplicationContext) applicationContext; ctx.addApplicationListener(this); } }
@Component public class BeanInWebContext implements ApplicationListener<SomeEvent> { @Autowired private ApplicationContext webContext; @PostConstruct public void registerAsListener() { // get parent context AbstractApplicationContext appContext = (AbstractApplicationContext) webContext.getParent(); // register self as a listener, this method is in AbstractApplicationContext appContext.addApplicationListener(this); } @Override public void onApplicationEvent(SomeEvent event) { } }
@Override public Object postProcessAfterInitialization(Object bean, String beanName) { if (bean instanceof ApplicationListener) { // potentially not detected as a listener by getBeanNamesForType retrieval Boolean flag = this.singletonNames.get(beanName); if (Boolean.TRUE.equals(flag)) { // singleton bean (top-level or inner): register on the fly this.applicationContext.addApplicationListener((ApplicationListener<?>) bean); } else if (Boolean.FALSE.equals(flag)) { if (logger.isWarnEnabled() && !this.applicationContext.containsBean(beanName)) { // inner bean with other scope - can't reliably process events logger.warn("Inner bean '" + beanName + "' implements ApplicationListener interface " + "but is not reachable for event multicasting by its containing ApplicationContext " + "because it does not have singleton scope. Only top-level listener beans are allowed " + "to be of non-singleton scope."); } this.singletonNames.remove(beanName); } } return bean; }
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { if (loader.components == null) { WebxComponentsImpl components = loader.createComponents(loader.getParentConfiguration(), beanFactory); AbstractApplicationContext wcc = (AbstractApplicationContext) components.getParentApplicationContext(); wcc.addApplicationListener(new SourceFilteringListener(wcc, components)); loader.components = components; } }
private void wrapInternalBeanFactoryInApplicationContext(DefaultJavaConfigBeanFactory internalBeanFactory) { final AbstractApplicationContext internalContext = new GenericApplicationContext(internalBeanFactory); internalContext.setDisplayName("JavaConfig internal application context"); // add a listener that triggers this child context to refresh when the parent refreshes. // this will cause any BeanPostProcessors / BeanFactoryPostProcessors to be beansInvokedFor // on the beans in the child context. externalContext.addApplicationListener(new ChildContextRefreshingListener(externalContext, internalContext, ignoredBeanPostProcessors)); }
ctx.addApplicationListener(listener); ApplicationContext ac = applicationContext.getParent(); while (ac != null) { if (ac instanceof AbstractApplicationContext) { ((AbstractApplicationContext)ac).addApplicationListener(listener);
delegatedBeanApplicationContext.addApplicationListener(this);
ctx.addApplicationListener(listener); ApplicationContext ac = applicationContext.getParent(); while (ac != null) { if (ac instanceof AbstractApplicationContext) { ((AbstractApplicationContext)ac).addApplicationListener(listener);
ctx.addApplicationListener(listener); ApplicationContext ac = applicationContext.getParent(); while (ac != null) { if (ac instanceof AbstractApplicationContext) { ((AbstractApplicationContext)ac).addApplicationListener(listener);
delegatedBeanApplicationContext.addApplicationListener(this);
ctx.addApplicationListener(listener); ApplicationContext ac = applicationContext.getParent(); while (ac != null) { if (ac instanceof AbstractApplicationContext) { ((AbstractApplicationContext)ac).addApplicationListener(listener);