如何解决EclipseLink(MOXy)的“获取属性“ eclipselink.oxm.metadata-source”不支持'? [英] How do I solve EclipseLink's (MOXy) 'getting property "eclipselink.oxm.metadata-source" is not supported'?

查看:103
本文介绍了如何解决EclipseLink(MOXy)的“获取属性“ eclipselink.oxm.metadata-source”不支持'?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

主要根据EclipseLink网站上的教程,我整理了以下代码:

I've got the following piece of code which I've put together mainly based on tutorials on EclipseLink's website:

    Partner p = new Partner();
    p.setId(1);
    p.setKey("a");
    p.setName("this is the name");

    Map<String, Source> metadataSourceMap = new HashMap<String, Source>();
    metadataSourceMap.put("com.company.pas.entity.partner", new StreamSource("/com/company/pas/entity/mapping/partner-pojo2xml.xml"));
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put(JAXBContextProperties.OXM_METADATA_SOURCE, metadataSourceMap);
    JAXBContext jaxbContext = JAXBContext.newInstance(new Class[] {Partner.class}, properties);

当我尝试运行这段代码时,我得到的只是一个例外:

When I try to run this piece of code, all I get is an exception:

Exception in thread "main" javax.xml.bind.JAXBException: property "eclipselink.oxm.metadata-source" is not supported
    at com.sun.xml.internal.bind.v2.ContextFactory.createContext(ContextFactory.java:115)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:248)
    at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:235)
    at javax.xml.bind.ContextFinder.find(ContextFinder.java:445)
    at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:637)

我还没有在此处包括映射文件(partner-pojo2xml.xml),因为无论是否将映射文件添加到 metaDataSourceMap ,都会发生异常。

I haven't included the "mapping file" (partner-pojo2xml.xml) here, as the exception occurs regardless of whether the mapping file is added to the metaDataSourceMap or not.

可从下面找到pom.xml中的相关部分。

The relevant part from pom.xml can be found below.

<dependency>
    <groupId>org.eclipse.persistence</groupId>
    <artifactId>eclipselink</artifactId>
    <version>2.5.1</version>
</dependency>   

我在做什么错?我尝试了太多组合,但我无法使其运行。

What am I doing wrong? I've tried too many combinations, but I just can't get it to run.

推荐答案

您需要确保自己有一个 jaxb.properties 文件,其中包含以下条目:

You need to be sure you have a jaxb.properties file with the following entry:

javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory

使用时该文件必须位于与用于引导 JAXBContext 的类的包名称匹配的目录结构中。该结构需要放在 src / main / resources 文件夹下。以下是我在GitHub中的示例的链接:

When you are using Maven this file needs to be in a directory structure matching the package name of the classes used to bootstrap the JAXBContext. This structure needs to go under the src/main/resources folder. Below is a link to an example I have in GitHub:

  • https://github.com/bdoughan/blog20110322

这篇关于如何解决EclipseLink(MOXy)的“获取属性“ eclipselink.oxm.metadata-source”不支持'?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆