web-services - java webservice jax-ws 什么时候需要@webmethod
问题描述
我正在尝试理解JAX-WS
并且很难理解@WebMethod
Annotation 的目的。
这是示例代码:
@WebService
@SOAPBinding(style = SOAPBinding.Style.DOCUMENT)
public class TestServiceImpl {
public String greet1(String msg) {
return "greet1";
}
@WebMethod
public String greet3(String msg) {
return "greet3";
}
public String greet5(String msg) {
return "greet5";
}
}
当我查看时,WSDL
我可以看到所有 3 种方法'greet1'
并且'greet3'
没有@WebMethod
注释。只有 'greet2'
有注释。
这是WSDL
:
<binding name="TestServiceImplPortBinding" type="tns:TestServiceImpl">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"
style="document"/>
<operation name="greet5"></operation>
<operation name="greet3"></operation>
<operation name="greet1"></operation>
</binding>
所以不确定 WebMethod 注释的用途是什么?
解决方案
@WebMethod
注释由 Web 服务引擎在内部使用,以将任何公共方法公开为 Web 服务操作。正如 JEE 规范中所说:
@WebMethod 指定该方法作为 Web 服务的公共操作公开。你必须显式地使用这个注解来暴露一个方法;
如果不指定此注解,则默认不公开该方法。
但是,根据我的实践,一些应用程序服务器(例如 IBM WebSphere 和一些 WS 引擎)将您的方法公开为 Web 服务操作,即使您没有在方法签名之前放置此类注释。我想这取决于 JAX-WS 实现。
这意味着使用注释注释public
的类中的任何方法@WebService
都将作为 Web 服务操作公开。为避免这种行为,您应该使用 显式注释方法@WebMethod(exclude=true)
。
推荐阅读
- firebase - Google Translate API 和 Firebase Firestore 互相残杀
- javascript - 仅当音频链接正常时才从播放更改为暂停
- hibernate - Hibernate 通过将 previous 增加 100 来生成下一个序列号
- tizen - Galaxy 手表无法连接到 Tizen Studio
- asp.net - Sitecore 9.1 安装 SitecoreInstallFramework
- html - 导航栏不会向右侧移动
- selenium - 如何做登录测试自动化框架。
- oracle - Oracle Plsql 中的 Web 服务调用问题
- android - Persistent BottomSheet:滑动以展开问题
- python-2.7 - inegers 列表的嵌套列表 - 进行算术运算