18
18
19
19
import java .util .concurrent .Executor ;
20
20
21
- import org .springframework .beans .factory . BeanFactory ;
21
+ import org .springframework .beans .BeansException ;
22
22
import org .springframework .beans .factory .BeanNameAware ;
23
23
import org .springframework .beans .factory .config .AbstractFactoryBean ;
24
+ import org .springframework .context .ApplicationContext ;
25
+ import org .springframework .context .ApplicationContextAware ;
24
26
import org .springframework .context .ApplicationEventPublisher ;
25
27
import org .springframework .context .ApplicationEventPublisherAware ;
26
28
import org .springframework .context .Lifecycle ;
57
59
* @since 2.0.5
58
60
*/
59
61
public class TcpConnectionFactoryFactoryBean extends AbstractFactoryBean <AbstractConnectionFactory >
60
- implements Lifecycle , BeanNameAware , ApplicationEventPublisherAware {
62
+ implements Lifecycle , BeanNameAware , ApplicationEventPublisherAware , ApplicationContextAware {
61
63
62
64
private AbstractConnectionFactory connectionFactory ;
63
65
@@ -125,10 +127,10 @@ public class TcpConnectionFactoryFactoryBean extends AbstractFactoryBean<Abstrac
125
127
126
128
private ApplicationEventPublisher applicationEventPublisher ;
127
129
128
- private BeanFactory beanFactory ;
129
-
130
130
private Integer connectTimeout ;
131
131
132
+ private ApplicationContext applicationContext ;
133
+
132
134
133
135
public TcpConnectionFactoryFactoryBean () {
134
136
}
@@ -138,8 +140,8 @@ public TcpConnectionFactoryFactoryBean(String type) {
138
140
}
139
141
140
142
@ Override
141
- public final void setBeanFactory ( BeanFactory beanFactory ) {
142
- this .beanFactory = beanFactory ;
143
+ public void setApplicationContext ( ApplicationContext applicationContext ) throws BeansException {
144
+ this .applicationContext = applicationContext ;
143
145
}
144
146
145
147
@ Override
@@ -154,7 +156,7 @@ public Class<?> getObjectType() {
154
156
@ Override
155
157
protected AbstractConnectionFactory createInstance () {
156
158
if (!this .mapperSet ) {
157
- this .mapper .setBeanFactory (this . beanFactory );
159
+ this .mapper .setBeanFactory (getBeanFactory () );
158
160
}
159
161
if (this .usingNio ) {
160
162
if (isServer ()) {
@@ -197,6 +199,11 @@ protected AbstractConnectionFactory createInstance() {
197
199
this .connectionFactory = factory ;
198
200
}
199
201
}
202
+ this .connectionFactory .setBeanFactory (getBeanFactory ());
203
+ if (this .applicationContext != null ) {
204
+ this .connectionFactory .setApplicationContext (this .applicationContext );
205
+ }
206
+ this .connectionFactory .afterPropertiesSet ();
200
207
return this .connectionFactory ;
201
208
}
202
209
0 commit comments