spring oxm会创建singleton jaxbcontext吗?

时间:2016-09-14 04:57:59

标签: spring jaxb2 spring-oxm

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

1 个答案:

答案 0 :(得分:0)

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