Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
484 views
in Technique[技术] by (71.8m points)

java - XmlElement annotation dissallowed with WebParam

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...