Skip to content

Commit 6e9f324

Browse files
committed
* Use getChannelResolver() internally in the AbstractMethodAnnotationPostProcessor
instead of direct property access which might not be initialized yet * Use a plain `boolean` for `templateInitialized` in the `MessagePublishingInterceptor` to avoid skips in other thread where and move on with still not initialized properties
1 parent e6c6db1 commit 6e9f324

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

spring-integration-core/src/main/java/org/springframework/integration/aop/MessagePublishingInterceptor.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,18 @@ public class MessagePublishingInterceptor implements MethodInterceptor, BeanFact
6565

6666
private final PublisherMetadataSource metadataSource;
6767

68-
private final AtomicBoolean templateInitialized = new AtomicBoolean();
69-
7068
private DestinationResolver<MessageChannel> channelResolver;
7169

7270
private BeanFactory beanFactory;
7371

7472
private MessageBuilderFactory messageBuilderFactory = new DefaultMessageBuilderFactory();
7573

76-
private boolean messageBuilderFactorySet;
77-
7874
private String defaultChannelName;
7975

76+
private volatile boolean messageBuilderFactorySet;
77+
78+
private volatile boolean templateInitialized;
79+
8080
public MessagePublishingInterceptor(PublisherMetadataSource metadataSource) {
8181
Assert.notNull(metadataSource, "metadataSource must not be null");
8282
this.metadataSource = metadataSource;
@@ -144,11 +144,12 @@ public final Object invoke(MethodInvocation invocation) throws Throwable {
144144
}
145145

146146
private void initMessagingTemplateIfAny() {
147-
if (this.templateInitialized.compareAndSet(false, true)) {
147+
if (!this.templateInitialized) {
148148
this.messagingTemplate.setBeanFactory(beanFactory);
149149
if (this.channelResolver == null) {
150150
this.channelResolver = ChannelResolverUtils.getChannelResolver(this.beanFactory);
151151
}
152+
this.templateInitialized = true;
152153
}
153154
}
154155

spring-integration-core/src/main/java/org/springframework/integration/config/AbstractMethodAnnotationPostProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ protected AbstractEndpoint createEndpoint(MessageHandler handler, @SuppressWarni
572572
if (StringUtils.hasText(inputChannelName)) {
573573
MessageChannel inputChannel;
574574
try {
575-
inputChannel = this.channelResolver.resolveDestination(inputChannelName);
575+
inputChannel = getChannelResolver().resolveDestination(inputChannelName);
576576
}
577577
catch (DestinationResolutionException e) {
578578
if (e.getCause() instanceof NoSuchBeanDefinitionException) {

0 commit comments

Comments
 (0)