首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >spring oxm会创建单例jaxbcontext吗?

spring oxm会创建单例jaxbcontext吗?
EN

Stack Overflow用户
提问于 2016-09-14 12:57:59
回答 1查看 185关注 0票数 0

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

EN

回答 1

Stack Overflow用户

发布于 2016-09-14 17:45:58

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

代码语言:javascript
复制
    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;
            }
        }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39482755

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档