Sunday, 15 September 2013

Spring how to inject a bean for a Handler of xsocket?

Spring how to inject a bean for a Handler of xsocket?

I use xsocket to implement a socket server, and the handler of xsocket
need inject an bean to do something. But, the reference aliway be NULL, I
had logged the setter method, the setter method had been excused and the
bean is not null in the log.
public class SocketServerHandler implements IDataHandler, IConnectHandler,
IIdleTimeoutHandler, IConnectionTimeoutHandler, IDisconnectHandler,
ApplicationContextAware {
private APIInvokeServer apiInvokeServer;
@Override
public boolean onData(INonBlockingConnection connection) throws
IOException, BufferUnderflowException,ClosedChannelException,
MaxReadSizeExceededException {
// read from connection
String message = parseMessage(connection);
final APIInvokeRequest invokeRequest;
invokeRequest = apiInvokeServer.createInvokeRequest(trace);
balabala...
}
public void setApiInvokeServer(APIInvokeServer apiInvokeServer) {
OceanLog.system.error("--------setApiInvokeServer--------" +
apiInvokeServer);
this.apiInvokeServer = apiInvokeServer;
}
}
and spring xml file:
<bean id="socketServerHandler"
class="com.alibaba.ocean.listener.socket.SocketServerHandler">
<property name="apiInvokeServer" ref="apiInvokeServer"/>
</bean>
The log white:
--------setApiInvokeServer--------com.alibaba.openapi.invoke.server.DefaultAPIInvokeServer@468a169f
thus, setter method has been called, but why when I debug the code,
apiInvokeServer is NULL???

No comments:

Post a Comment