|
32 | 32 |
|
33 | 33 | import org.springframework.beans.BeansException;
|
34 | 34 | import org.springframework.beans.factory.BeanClassLoaderAware;
|
| 35 | +import org.springframework.beans.factory.BeanFactory; |
| 36 | +import org.springframework.beans.factory.HierarchicalBeanFactory; |
35 | 37 | import org.springframework.beans.factory.SmartInitializingSingleton;
|
36 | 38 | import org.springframework.beans.factory.config.BeanDefinition;
|
37 | 39 | import org.springframework.beans.factory.config.BeanDefinitionHolder;
|
@@ -172,18 +174,21 @@ private void registerMessagePublishingErrorHandler() {
|
172 | 174 | private void registerNullChannel() {
|
173 | 175 | if (this.beanFactory.containsBean(IntegrationContextUtils.NULL_CHANNEL_BEAN_NAME)) {
|
174 | 176 | BeanDefinition nullChannelDefinition = null;
|
175 |
| - if (this.beanFactory.containsBeanDefinition(IntegrationContextUtils.NULL_CHANNEL_BEAN_NAME)) { |
176 |
| - nullChannelDefinition = |
177 |
| - this.beanFactory.getBeanDefinition(IntegrationContextUtils.NULL_CHANNEL_BEAN_NAME); |
178 |
| - } |
179 |
| - else { |
180 |
| - BeanDefinitionRegistry parentBeanFactory = |
181 |
| - (BeanDefinitionRegistry) this.beanFactory.getParentBeanFactory(); |
182 |
| - if (parentBeanFactory != null) { |
183 |
| - nullChannelDefinition = |
184 |
| - parentBeanFactory.getBeanDefinition(IntegrationContextUtils.NULL_CHANNEL_BEAN_NAME); |
| 177 | + BeanFactory beanFactory = this.beanFactory; |
| 178 | + do { |
| 179 | + if (beanFactory instanceof ConfigurableListableBeanFactory) { |
| 180 | + ConfigurableListableBeanFactory listable = (ConfigurableListableBeanFactory) beanFactory; |
| 181 | + if (listable.containsBeanDefinition(IntegrationContextUtils.NULL_CHANNEL_BEAN_NAME)) { |
| 182 | + nullChannelDefinition = listable |
| 183 | + .getBeanDefinition(IntegrationContextUtils.NULL_CHANNEL_BEAN_NAME); |
| 184 | + } |
185 | 185 | }
|
186 |
| - } |
| 186 | + // don't think it will hurt to always find the parent |
| 187 | + if (beanFactory instanceof HierarchicalBeanFactory) { |
| 188 | + beanFactory = ((HierarchicalBeanFactory) beanFactory).getParentBeanFactory(); |
| 189 | + } |
| 190 | + // will definitely be found as containsBean returned true - but also want to be defensive in case of NPE |
| 191 | + } while (nullChannelDefinition == null && beanFactory != null); // not sure if beanFactroy not null is necessary |
187 | 192 |
|
188 | 193 | if (nullChannelDefinition != null &&
|
189 | 194 | !NullChannel.class.getName().equals(nullChannelDefinition.getBeanClassName())) {
|
|
0 commit comments