【问题标题】:Does spring oxm creates singleton jaxbcontext?spring oxm 是否创建单例 jaxbcontext?
【发布时间】:2016-09-14 04:57:59
【问题描述】:

在 Spring OXM 框架内部,JAXBContext.newInstance() 是如何创建的。是单例还是多例。我的要求是我想要单身jaxbcontext 对象?请分享 Spring OXM 的详细信息。谢谢。

【问题讨论】:

    标签: spring jaxb2 spring-oxm


    【解决方案1】:

    我得到了答案,它在 Jaxb2Marshaller 内部创建单例 jaxb 上下文,如下所示:

        public JAXBContext getJaxbContext() {
                if (this.jaxbContext != null) {
                    return this.jaxbContext;
                }
                synchronized (this.jaxbContextMonitor) {
                    if (this.jaxbContext == null) {
                        try {
                            if (StringUtils.hasLength(this.contextPath)) {
                                this.jaxbContext = createJaxbContextFromContextPath();
                            }
                            else if (!ObjectUtils.isEmpty(this.classesToBeBound)) {
                                this.jaxbContext = createJaxbContextFromClasses();
                            }
                            else if (!ObjectUtils.isEmpty(this.packagesToScan)) {
                                this.jaxbContext = createJaxbContextFromPackages();
                            }
                        }
                        catch (JAXBException ex) {
                            throw convertJaxbException(ex);
                        }
                    }
                    return this.jaxbContext;
                }
            }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-06
      • 1970-01-01
      • 1970-01-01
      • 2011-07-20
      • 2012-07-17
      • 1970-01-01
      相关资源
      最近更新 更多