0

Spring OXM フレームワーク内でどのようにJAXBContext.newInstance()作成しますか。それはシングルトンまたは複数のインスタンスですか。私の要件は、シングルトンjaxbcontextオブジェクトが欲しいですか? Spring OXM の詳細を共有してください。ありがとう。

4

1 に答える 1

0

次のように、内部でシングルトン jaxb コンテキストを作成していますJaxb2Marshaller

    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;
            }
        }
于 2016-09-14T09:45:57.607 に答える