spring oxm是否创建了单例jaxbcontext ?



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

我得到了答案,它在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;
            }
        }

相关内容

  • 没有找到相关文章

最新更新