WebParam 不允许使用 XmlElement 注释
我在网络服务中有一个方法,具有以下签名:
@WebResult(name="purchaseId") public int CreatePurchase(
@XmlElement(required=true)
@WebParam(name = "item") String item {
...
}
在我看来(根据我发现的信息),这个应该可以工作。不幸的是,我在编译时收到以下错误消息:
The annotation @XmlElement is disallowed for this location
有谁知道如何解决该问题?
I have a method inside a webservice, with the following signature:
@WebResult(name="purchaseId") public int CreatePurchase(
@XmlElement(required=true)
@WebParam(name = "item") String item {
...
}
It seems to me (based on what information i've found) that this should work. Unfortunately, I get the following error message on compilation:
The annotation @XmlElement is disallowed for this location
Does anyone know how to resolve the issue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
默认情况下,JAX-B 包含在 JDK 中。特定 JDK 附带的版本的更新频率几乎不及 JAX-B 本身。 JDK (1.6) 附带的当前版本是 JAX-B 2.1.10(记录在此处)。
@XmlElement 仅允许在从 JAX-B 2.2 开始的方法参数上使用。
当 Java 加载库时,它会先加载 JDK 附带的库,然后再加载类路径上的库。升级到 Java 7 可以解决您的问题。如果您无法升级到 Java 7,还有一个过程可以告诉 Java 您想要使用更新的库。这些称为“认可”库,您必须将这些库放在同一个库中。文件夹结构与 JDK 本身相同。 此处描述了该过程。
JAX-B is included with a JDK by default. The version that comes with the particular JDK isn't updated nearly as frequently as JAX-B itself. The current version that comes with the JDK (1.6) is JAX-B 2.1.10 (documented here).
@XmlElement is only allowed on method parameters starting with JAX-B 2.2
When Java loads libaries it loads libraries that come with the JDK before it loads libraries that are on the classpath. Upgrdading to Java 7 would fix your problem. There is also a process for telling Java that you want to use a more up-to-date library if you aren't able to upgrade to Java 7. These are called "endorsed" libraries and you have to put the library in the same folder structure as the JDK itself. The process is described here.
当您收到以下错误消息:“此位置不允许使用注释@XmlElement”时,很可能您使用了错误的导入语句。
将其更改为:
由于 Eclipse 建议将另一个包作为第一个选项,这是一个非常常见的错误。
When you are having the following error message: "The annotation @XmlElement is disallowed for this location", chances are that you're using the wrong import statement.
Change it to:
As Eclipse suggests another package as the first option, it's a very common mistake.