Skip to content

Commit 4390591

Browse files
wilkinsonarstoyanchev
authored andcommitted
Make BeanFactoryMCDR BeanFactoryAware
SI's BeanFactoryChannelResolver was BeanFactoryAware. This commit brings Spring's BeanFactoryMessageChannelDestinationResolver in line with the old SI class.
1 parent b8bfabd commit 4390591

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

spring-messaging/src/main/java/org/springframework/messaging/core/BeanFactoryMessageChannelDestinationResolver.java

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import org.springframework.beans.BeansException;
1919
import org.springframework.beans.factory.BeanFactory;
20+
import org.springframework.beans.factory.BeanFactoryAware;
2021
import org.springframework.messaging.MessageChannel;
2122
import org.springframework.util.Assert;
2223

@@ -25,11 +26,34 @@
2526
* @author Mark Fisher
2627
* @since 4.0
2728
*/
28-
public class BeanFactoryMessageChannelDestinationResolver implements DestinationResolver<MessageChannel> {
29+
public class BeanFactoryMessageChannelDestinationResolver implements DestinationResolver<MessageChannel>, BeanFactoryAware {
2930

30-
private final BeanFactory beanFactory;
31+
private volatile BeanFactory beanFactory;
3132

33+
/**
34+
* Create a new instance of the {@link
35+
* BeanFactoryMessageChannelDestinationResolver} class.
36+
* <p>The BeanFactory to access must be set via <code>setBeanFactory</code>.
37+
* This will happen automatically if this resolver is defined within an
38+
* ApplicationContext thereby receiving the callback upon initialization.
39+
*
40+
* @see #setBeanFactory
41+
*/
42+
public BeanFactoryMessageChannelDestinationResolver() {
3243

44+
}
45+
46+
/**
47+
* Create a new instance of the {@link
48+
* BeanFactoryMessageChannelDestinationResolver} class.
49+
* <p>Use of this constructor is redundant if this object is being created
50+
* by a Spring IoC container as the supplied {@link BeanFactory} will be
51+
* replaced by the {@link BeanFactory} that creates it (c.f. the
52+
* {@link BeanFactoryAware} contract). So only use this constructor if you
53+
* are instantiating this object explicitly rather than defining a bean.
54+
*
55+
* @param beanFactory the bean factory to be used to lookup {@link MessageChannel}s.
56+
*/
3357
public BeanFactoryMessageChannelDestinationResolver(BeanFactory beanFactory) {
3458
Assert.notNull(beanFactory, "beanFactory must not be null");
3559
this.beanFactory = beanFactory;
@@ -48,4 +72,9 @@ public MessageChannel resolveDestination(String name) {
4872
}
4973
}
5074

75+
@Override
76+
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
77+
this.beanFactory = beanFactory;
78+
}
79+
5180
}

0 commit comments

Comments
 (0)