I'm encountering a JAXBException only when running a scheduled task in development environment with JobRunr on JDK 17 and Spring Boot, deployed on Azure. The issue does not occur when I call the same method through a controller or locally.
**Issue: ** In dev environment, during a JobRunr cron job execution, I face:
javax.xml.bind.JAXBException: Implementation of JAXB-API has not been found on module path or classpath.
**What I've Tried: ** Confirmed JAXB dependencies in pom.xml (using org.glassfish.jaxb:jaxb-runtime:4.0.5).
Printed classpath and ClassLoader details during both controller and cron job execution. Results are identical:
This error arises despite using the same code to create a JAXBContext instance:
try {
JAXBContext jc = JAXBContext.newInstance(MrwServiceImpl.class);
LOG.error("JAXBContext: {}", jc);
} catch (JAXBException e) {
LOG.error("Error al crear JAXBContext", e);
}
While executing locally or from controller:
2024-03-16T12:09:36.688Z ERROR 128 --- [http-nio-80-exec-5] e.a.s.api.service.impl.TestServiceImpl : JAXBContext: jar:file:/home/site/wwwroot/app.jar!/BOOT-INF/lib/jaxb-impl-4.0.2.jar!/org/glassfish/jaxb/runtime/v2/runtime/JAXBContextImpl.class Build-Id: 4.0.2 - d104f19
Classes known to this context:
[B
boolean
byte
char
double
es.miapp.shippingservices.api.service.impl.TestServiceImpl
float
int
jakarta.activation.DataHandler
jakarta.xml.bind.JAXBElement
java.awt.Image
java.io.File
java.lang.Boolean
java.lang.Byte
java.lang.Character
java.lang.Class
java.lang.Double
java.lang.Float
java.lang.Integer
java.lang.Long
java.lang.Object
java.lang.Short
java.lang.String
java.lang.Void
java.math.BigDecimal
java.math.BigInteger
java.net.URI
java.net.URL
java.util.Calendar
java.util.Date
java.util.GregorianCalendar
java.util.UUID
javax.xml.datatype.Duration
javax.xml.datatype.XMLGregorianCalendar
javax.xml.namespace.QName
javax.xml.transform.Source
long
org.glassfish.jaxb.runtime.api.CompositeStructure
short
void
ClassPath: /home/site/wwwroot/app.jar:/usr/local/appservice/lib/azure.appservice.jar
Class Loader: org.springframework.boot.loader.LaunchedURLClassLoader
Inspected and logged environment variables and system properties, but no significant differences were found.
Added explicit logging around JAXBContext creation and other JAXB operations.
Checked for potential conflicts in class loading and Spring configurations.
Ran successfully in the local environment against the dev setup.
**Question: ** How can I ensure the correct JAXB implementation is available in the classpath during JobRunr cron executions in a production Azure environment? Are there specific configurations or environment conditions in Azure or JobRunr that could affect class loading differently compared to a local run or controller-invoked method?
Any insights into solving this perplexing behavior will be greatly appreciated!
If you have
javax.xml.bind.JAXBExceptionexception and having jaxb-ri 4.x in your classpath, you've mixed jaxb-api and jaxb-ri.I'm pretty sure your application use jaxb-api 2.x but runtime is 4.x which are incompatible.
Depending of SpringBoot version, you should downgrade jaxb-ri to 2.x (2.3.9) if targeting SpringBoot 2.x or upgrade jaxb-api to 4.x (4.0.2) if targeting SpringBoot 3.x