简体   繁体   中英

Does spring oxm creates singleton jaxbcontext?

Inside Spring OXM framework how does JAXBContext.newInstance() creates. Is it a singleton or multiple instance. My requirement is I want singleton jaxbcontext object? Please share Spring OXM details. Thanks.

I got the answer, it's creating singleton jaxb context internally inside Jaxb2Marshaller , like this:

    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;
            }
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM