我想在我的java类中注释我的java方法为@XmlTransient
,如下所示。在Jaxb 2.1中使用@XmlTransient注释java方法时的问题2.1
@XmlAccessorType(XmlAccessType.PROPERTY)
public abstract class MyClass {
@XmlTransient
public void addsomething{
// do something
}
}
当我尝试通过其他类我的JAXBContext来使用这个类我得到以下异常
JAXB annotation is placed on a method that is not a JAXB property
this problem is related to the following location:
at @javax.xml.bind.annotation.XmlTransient()
,
但是,当我看到XmlTransient()
注释定义(@Target(value={FIELD,METHOD,TYPE}))
这显然说是使用方法。而在Javadoc(http://docs.oracle.com/javaee/7/api/javax/xml/bind/annotation/XmlTransient.html)它说
The @XmlTransient annotation can be used with the following program elements:
a JavaBean property
field
class
我不能使用的方法@XmlTransient
?
没有:),因为Javadoc说你不能这么做 – WeMakeSoftware
为什么你要将'XmlTransient'添加到'void'方法? –