我在 DTO 类中遇到循环错误,因此决定实现 MOXy 来消除它。我按照以下步骤实现 MOXy:
已从 [ http://www.eclipse.org/eclipselink/downloads/nightly.php 下载 EclipseLink ]
将/eclipselink/jlib 文件夹中的所有 JAR 复制到我的/WEB-INF/lib
为了将 EclipseLink MOXy 指定为 JAXB 提供程序,在所有类都存在的文件夹中创建了一个 jaxb.properties 文件,其中包含以下条目 -
javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory
我在 dto 类中使用 @XmlElement 和 @XmlInverseReference 注释,但在运行应用程序时遇到以下错误:
javax.ws.rs.WebApplicationException: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions, Class has two properties of the same name "application"
this problem is related to the following location:
at public thbs.provisioning.dto.ApplicationDTO thbs.provisioning.dto.EnvironmentDTO.getApplication()
at thbs.provisioning.dto.EnvironmentDTO
at public java.util.Set thbs.provisioning.dto.ApplicationDTO.getEnvironment()
at thbs.provisioning.dto.ApplicationDTO
this problem is related to the following location:
at private thbs.provisioning.dto.ApplicationDTO thbs.provisioning.dto.EnvironmentDTO.application
at thbs.provisioning.dto.EnvironmentDTO
at public java.util.Set thbs.provisioning.dto.ApplicationDTO.getEnvironment()
at thbs.provisioning.dto.ApplicationDTO
最佳答案
由于某种原因,您的 jaxb.properties
文件未被选取 - 错误消息中的“com.sun.xml.bind.v2.runtime”表明 Sun JAXB 正在运行,不是 MOXy。
确保 jaxb.properties
位于与模型类相同的包中的类路径中。如果您在源目录中包含了 jaxb.properties
,请确保将其复制到 .class
文件所在的同一目录中。您可以在此处阅读有关设置 jaxb.properties
的信息:http://www.eclipse.org/eclipselink/documentation/2.5/moxy/runtime.htm#sthref8
希望这有帮助, 瑞克
关于java - 实现 MOXy 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17521161/