程序问答   发布时间:2022-06-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了我可以用代码替换jaxb.properties吗?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决我可以用代码替换jaxb.properties吗??

开发过程中遇到我可以用代码替换jaxb.properties吗?的问题如何解决?下面主要结合日常开发的经验,给出你关于我可以用代码替换jaxb.properties吗?的解决方法建议,希望对你解决我可以用代码替换jaxb.properties吗?有所启发或帮助;

您可以执行以下操作以获取JAXBContext没有jaxb.propertIEs文件的Eclipselink JAXB(MOXy):

import java.io.file;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;

import org.eclipse.persistence.jaxb.JAXBContextFactory;

public class Demo {

    public static voID main(String[] args) throws Exception {
        //JAXBContext jc = JAXBContext.newInstance(Animals.class);
        JAXBContext jc = JAXBContextFactory.createContext(new Class[] {Animals.class}, null);

        Unmarshaller unmarshaller = jc.createUnmarshaller();
        file xml = new file("src/forum6871469/input.xml");
        Animals animals = (Animals) unmarshaller.unmarshal(xml);

        Marshaller marshaller = jc.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, truE);
        marshaller.marshal(animals, System.out);
    }

}

解决方法

我正在使用
EclipseLink的JAXB实现的一些非标准扩展,并且要启用该实现,必须使用jaxb.properties对其进行配置。效果很好。

但是,由于生成错误,属性文件未包含在正确的位置,从而导致使用默认的JAXB,该文件没有任何错误,只是继续解析XML文件,忽略了非标准扩展名,给我留下了一个非工作bean。

为了使它更加健壮,我想摆脱属性文件,并在代码中指定上下文配置。由于它们的注释,我已经对EclipseLink产生了编译时依赖性,并且我不需要在部署时就可以配置此部分(实际上,看到什么地方出了问题,我不希望它可配置)。

大佬总结

以上是大佬教程为你收集整理的我可以用代码替换jaxb.properties吗?全部内容,希望文章能够帮你解决我可以用代码替换jaxb.properties吗?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。