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.