18
18
19
19
import java .util .concurrent .Executor ;
20
20
21
- import org .springframework .beans .factory .BeanFactory ;
22
- import org .springframework .beans .factory .BeanFactoryAware ;
21
+ import org .springframework .beans .BeansException ;
23
22
import org .springframework .beans .factory .BeanNameAware ;
24
23
import org .springframework .beans .factory .config .AbstractFactoryBean ;
24
+ import org .springframework .context .ApplicationContext ;
25
+ import org .springframework .context .ApplicationContextAware ;
25
26
import org .springframework .context .ApplicationEventPublisher ;
26
27
import org .springframework .context .ApplicationEventPublisherAware ;
27
28
import org .springframework .context .SmartLifecycle ;
56
57
* @since 2.0.5
57
58
*/
58
59
public class TcpConnectionFactoryFactoryBean extends AbstractFactoryBean <AbstractConnectionFactory > implements SmartLifecycle , BeanNameAware ,
59
- BeanFactoryAware , ApplicationEventPublisherAware {
60
+ ApplicationEventPublisherAware , ApplicationContextAware {
60
61
61
62
private volatile AbstractConnectionFactory connectionFactory ;
62
63
@@ -74,7 +75,7 @@ public class TcpConnectionFactoryFactoryBean extends AbstractFactoryBean<Abstrac
74
75
75
76
private volatile boolean soTcpNoDelay ;
76
77
77
- private volatile int soLinger = -1 ; // don't set by default
78
+ private volatile int soLinger = -1 ; // don't set by default
78
79
79
80
private volatile boolean soKeepAlive ;
80
81
@@ -122,7 +123,8 @@ public class TcpConnectionFactoryFactoryBean extends AbstractFactoryBean<Abstrac
122
123
123
124
private volatile ApplicationEventPublisher applicationEventPublisher ;
124
125
125
- private volatile BeanFactory beanFactory ;
126
+
127
+ private ApplicationContext applicationContext ;
126
128
127
129
128
130
public TcpConnectionFactoryFactoryBean () {
@@ -133,23 +135,23 @@ public TcpConnectionFactoryFactoryBean(String type) {
133
135
}
134
136
135
137
@ Override
136
- public final void setBeanFactory ( BeanFactory beanFactory ) {
137
- this .beanFactory = beanFactory ;
138
+ public void setApplicationContext ( ApplicationContext applicationContext ) throws BeansException {
139
+ this .applicationContext = applicationContext ;
138
140
}
139
141
140
142
@ Override
141
143
public Class <?> getObjectType () {
142
144
return this .connectionFactory != null ? this .connectionFactory .getClass () :
143
- this .type == null ? AbstractConnectionFactory .class :
144
- isServer () ? AbstractServerConnectionFactory .class :
145
- isClient () ? AbstractClientConnectionFactory .class :
146
- AbstractConnectionFactory .class ;
145
+ this .type == null ? AbstractConnectionFactory .class :
146
+ isServer () ? AbstractServerConnectionFactory .class :
147
+ isClient () ? AbstractClientConnectionFactory .class :
148
+ AbstractConnectionFactory .class ;
147
149
}
148
150
149
151
@ Override
150
152
protected AbstractConnectionFactory createInstance () throws Exception {
151
153
if (!this .mapperSet ) {
152
- this .mapper .setBeanFactory (this . beanFactory );
154
+ this .mapper .setBeanFactory (getBeanFactory () );
153
155
}
154
156
if (this .usingNio ) {
155
157
if (isServer ()) {
@@ -188,6 +190,11 @@ protected AbstractConnectionFactory createInstance() throws Exception {
188
190
this .connectionFactory = connectionFactory ;
189
191
}
190
192
}
193
+ this .connectionFactory .setBeanFactory (getBeanFactory ());
194
+ if (this .applicationContext != null ) {
195
+ this .connectionFactory .setApplicationContext (this .applicationContext );
196
+ }
197
+ this .connectionFactory .afterPropertiesSet ();
191
198
return this .connectionFactory ;
192
199
}
193
200
0 commit comments