Skip to content

Commit f80ecf1

Browse files
garyrussellartembilan
authored andcommitted
Fix TcpConnectionFactory FactoryBean
- bean factory and application context were not injected - `afterPropertiesSet()` was not called **cherry-pick to all supported branches**
1 parent 0ec9859 commit f80ecf1

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

spring-integration-ip/src/main/java/org/springframework/integration/ip/config/TcpConnectionFactoryFactoryBean.java

+14-7
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@
1818

1919
import java.util.concurrent.Executor;
2020

21-
import org.springframework.beans.factory.BeanFactory;
21+
import org.springframework.beans.BeansException;
2222
import org.springframework.beans.factory.BeanNameAware;
2323
import org.springframework.beans.factory.config.AbstractFactoryBean;
24+
import org.springframework.context.ApplicationContext;
25+
import org.springframework.context.ApplicationContextAware;
2426
import org.springframework.context.ApplicationEventPublisher;
2527
import org.springframework.context.ApplicationEventPublisherAware;
2628
import org.springframework.context.Lifecycle;
@@ -57,7 +59,7 @@
5759
* @since 2.0.5
5860
*/
5961
public class TcpConnectionFactoryFactoryBean extends AbstractFactoryBean<AbstractConnectionFactory>
60-
implements Lifecycle, BeanNameAware, ApplicationEventPublisherAware {
62+
implements Lifecycle, BeanNameAware, ApplicationEventPublisherAware, ApplicationContextAware {
6163

6264
private AbstractConnectionFactory connectionFactory;
6365

@@ -125,10 +127,10 @@ public class TcpConnectionFactoryFactoryBean extends AbstractFactoryBean<Abstrac
125127

126128
private ApplicationEventPublisher applicationEventPublisher;
127129

128-
private BeanFactory beanFactory;
129-
130130
private Integer connectTimeout;
131131

132+
private ApplicationContext applicationContext;
133+
132134

133135
public TcpConnectionFactoryFactoryBean() {
134136
}
@@ -138,8 +140,8 @@ public TcpConnectionFactoryFactoryBean(String type) {
138140
}
139141

140142
@Override
141-
public final void setBeanFactory(BeanFactory beanFactory) {
142-
this.beanFactory = beanFactory;
143+
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
144+
this.applicationContext = applicationContext;
143145
}
144146

145147
@Override
@@ -154,7 +156,7 @@ public Class<?> getObjectType() {
154156
@Override
155157
protected AbstractConnectionFactory createInstance() {
156158
if (!this.mapperSet) {
157-
this.mapper.setBeanFactory(this.beanFactory);
159+
this.mapper.setBeanFactory(getBeanFactory());
158160
}
159161
if (this.usingNio) {
160162
if (isServer()) {
@@ -197,6 +199,11 @@ protected AbstractConnectionFactory createInstance() {
197199
this.connectionFactory = factory;
198200
}
199201
}
202+
this.connectionFactory.setBeanFactory(getBeanFactory());
203+
if (this.applicationContext != null) {
204+
this.connectionFactory.setApplicationContext(this.applicationContext);
205+
}
206+
this.connectionFactory.afterPropertiesSet();
200207
return this.connectionFactory;
201208
}
202209

0 commit comments

Comments
 (0)