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.
Asked
Active
Viewed 254 times
0

Ronan Boiteau
- 9,608
- 6
- 34
- 56

Bhupati Patel
- 1,400
- 2
- 13
- 18
1 Answers
0
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;
}
}

Ronan Boiteau
- 9,608
- 6
- 34
- 56

Bhupati Patel
- 1,400
- 2
- 13
- 18