Tomcat 9.x DBCP basicdatasource methods returning java.time.* cannot be mapped to JMX OpenType
I am trying to upgrade tomcat web container used by our application from version 8.5 to 9.x. We have JDBC resources defined on the context xml file which have JMX enabled. When the application starts up, exceptions are thrown while registering beans with MBeanServer due to java.time.Duration
not having a corresponding OpenType.
This happens for org.apache.tomcat.dbcp.dbcp2.BasicDataSource
which have methods that return values of type java.time.Duration
Exception:
Caused by: java.lang.IllegalArgumentException: Method org.apache.tomcat.dbcp.dbcp2.DataSourceMXBean.getMaxConnDuration has parameter or return type that cannot be translated into an OpenType
...
...
Caused by: javax.management.openmbean.OpenDataException: Cannot convert type: java.time.Duration
...
...
Caused by: javax.management.openmbean.OpenDataException: Cannot convert type: java.time.temporal.TemporalUnit
...
...
Caused by: javax.management.openmbean.OpenDataException: Recursive data structure, including java.time.Duration
https://docs.oracle.com/en/java/javase/12/docs/api/java.management/javax/management/openmbean/OpenType.html
https://tomcat.apache.org/tomcat-9.0-doc/api/org/apache/tomcat/dbcp/dbcp2/BasicDataSource.html
Is there a workaround for this?
Thanks!
We also struggled with this issue. Stumbled upon another question that was similar and someone mentioned a PR that lead us down the path of looking at commits in the tomcat project and the changelogs. If you look at the changelog for Tomcat 9.x you can find that for a dev/nightly release (at the time of this writing) of 9.0.59:
Revert the cherry-pick of JavaDoc fix from DBCP applied in 9.0.57 that broke the DataSourceMXBean by using a type that isn't supported by MXBeans. (markt)
If you are still struggling with this you could either try the latest dev/nightly build (not yet published in maven central) or use version 9.0.56, which is what we used, and it should resolve this issue.