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?
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.
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:
import javax.xml.bind.annotation.XmlElement;
As Eclipse suggests another package as the first option, it's a very common mistake.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With