Spring OXM 框架内部是如何JAXBContext.newInstance()
创建的。是单例还是多例。我的要求是我想要单例jaxbcontext
对象?请分享 Spring OXM 的详细信息。谢谢。
问问题
196 次
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 回答