在某些教程中(例如here,here和here)建议通过将JAX-WS端口转换为com.sun.xml.ws.Closeable
来关闭JAX-WS端口,例如
MyPortType port = MyService.getMyPort();
... do some operations on WS proxy ...
((com.sun.xml.ws.Closeable) port).close();
此方法不适用于JaxWsPortProxyFactoryBean
返回的代理,因为它只建议目标WS接口和javax.xml.ws.BindingProvider
。
所以我的问题是:是否有必要关闭端口(请记住它在应用程序中可重用)?如果最好关闭端口(并且可能使它无效?),如何正确组织端口的生命周期(通过实现创建的Spring代理将永远是单例)?
答案 0 :(得分:4)
com.sun.xml.ws.Closeable
的JavaDoc读取:
This signals the implementation of certain specs (like WS-ReliableMessaging and
WS-SecureConversation) to terminate sessions that they create during the life
time of a proxy object. This is not a mandatory operation, so the application
does not have to call this method.
另外Closing WSIT Reliable Messaging Connections注意:
Calling close() method provides a way for WSIT components, such as Reliable
Messaging and Secure Conversations to do clean-up activities related to client
instance. Sometimes calling close() can be avoided without harmful effects.
答案 1 :(得分:2)
不,我不相信这是必要的。由JAX-WS子系统来管理自己的生命周期,不需要关闭端口。
如果查看源代码,这与JaxWsPortProxyFactoryBean
的行为有关。它不会尝试在上下文关闭时执行任何操作,Spring FactoryBeans通常会这样做。