Skip to content
Advertisement

Tomcat and Tomcat dbcp issue after upgrade to v9.0.58

I’m getting this issue when upgrading Tomcat and Tomcat DBCP from v9.0.54 to v.9.0.58 with Java 11.

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2022-02-08T08:24:15,900Z ERROR [tartedMain] SpringApplication [SpringApplication.java:854] Application run failed
org.springframework.jmx.export.UnableToRegisterMBeanException: Unable to register MBean [org.apache.tomcat.dbcp.dbcp2.BasicDataSource@3b60547f] with key 'datasource'; nested exception is javax.management.NotCompliantMBeanException: org.apache.tomcat.dbcp.dbcp2.BasicDataSourceMXBean: Method org.apache.tomcat.dbcp.dbcp2.DataSourceMXBean.getSoftMinEvictableIdleDuration has parameter or return type that cannot be translated into an open type
    at org.springframework.jmx.export.MBeanExporter.registerBeanNameOrInstance(MBeanExporter.java:626)
    at org.springframework.jmx.export.MBeanExporter.lambda$registerBeans$2(MBeanExporter.java:552)
    at java.base/java.util.HashMap.forEach(HashMap.java:1336)
    at org.springframework.jmx.export.MBeanExporter.registerBeans(MBeanExporter.java:552)
    at org.springframework.jmx.export.MBeanExporter.afterSingletonsInstantiated(MBeanExporter.java:435)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:972)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:765)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:445)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:338)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1354)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1343)
    at com.wk.gbs.intakeportal.IntakePortalWarApplication.main(IntakePortalWarApplication.java:30)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
Caused by: javax.management.NotCompliantMBeanException: org.apache.tomcat.dbcp.dbcp2.BasicDataSourceMXBean: Method org.apache.tomcat.dbcp.dbcp2.DataSourceMXBean.getSoftMinEvictableIdleDuration has parameter or return type that cannot be translated into an open type
    at java.management/com.sun.jmx.mbeanserver.Introspector.throwException(Introspector.java:467)
    at java.management/com.sun.jmx.mbeanserver.MBeanAnalyzer.<init>(MBeanAnalyzer.java:120)
    at java.management/com.sun.jmx.mbeanserver.MBeanAnalyzer.analyzer(MBeanAnalyzer.java:102)
    at java.management/com.sun.jmx.mbeanserver.MXBeanIntrospector.getAnalyzer(MXBeanIntrospector.java:74)
    at java.management/com.sun.jmx.mbeanserver.MBeanIntrospector.getPerInterface(MBeanIntrospector.java:192)
    at java.management/com.sun.jmx.mbeanserver.MBeanSupport.<init>(MBeanSupport.java:138)
    at java.management/com.sun.jmx.mbeanserver.MXBeanSupport.<init>(MXBeanSupport.java:66)
    at java.management/com.sun.jmx.mbeanserver.Introspector.makeDynamicMBean(Introspector.java:203)
    at java.management/com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerObject(DefaultMBeanServerInterceptor.java:888)
    at java.management/com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerMBean(DefaultMBeanServerInterceptor.java:320)
    at java.management/com.sun.jmx.mbeanserver.JmxMBeanServer.registerMBean(JmxMBeanServer.java:522)
    at org.springframework.jmx.support.MBeanRegistrationSupport.doRegister(MBeanRegistrationSupport.java:138)
    at org.springframework.jmx.export.MBeanExporter.registerBeanInstance(MBeanExporter.java:672)
    at org.springframework.jmx.export.MBeanExporter.registerBeanNameOrInstance(MBeanExporter.java:616)
    ... 19 common frames omitted
Caused by: java.lang.IllegalArgumentException: Method org.apache.tomcat.dbcp.dbcp2.DataSourceMXBean.getSoftMinEvictableIdleDuration has parameter or return type that cannot be translated into an open type
    at java.management/com.sun.jmx.mbeanserver.ConvertingMethod.from(ConvertingMethod.java:46)
    at java.management/com.sun.jmx.mbeanserver.MXBeanIntrospector.mFrom(MXBeanIntrospector.java:84)
    at java.management/com.sun.jmx.mbeanserver.MXBeanIntrospector.mFrom(MXBeanIntrospector.java:54)
    at java.management/com.sun.jmx.mbeanserver.MBeanAnalyzer.initMaps(MBeanAnalyzer.java:137)
    at java.management/com.sun.jmx.mbeanserver.MBeanAnalyzer.<init>(MBeanAnalyzer.java:118)
    ... 31 common frames omitted
Caused by: javax.management.openmbean.OpenDataException: Cannot convert type: java.time.Duration
    at java.management/com.sun.jmx.mbeanserver.DefaultMXBeanMappingFactory.openDataException(DefaultMXBeanMappingFactory.java:1445)
    at java.management/com.sun.jmx.mbeanserver.DefaultMXBeanMappingFactory.mappingForType(DefaultMXBeanMappingFactory.java:261)
    at java.management/com.sun.jmx.mbeanserver.ConvertingMethod.<init>(ConvertingMethod.java:212)
    at java.management/com.sun.jmx.mbeanserver.ConvertingMethod.from(ConvertingMethod.java:41)
    ... 35 common frames omitted
Caused by: javax.management.openmbean.OpenDataException: Cannot convert type: java.util.List<java.time.temporal.TemporalUnit>
    at java.management/com.sun.jmx.mbeanserver.DefaultMXBeanMappingFactory.openDataException(DefaultMXBeanMappingFactory.java:1445)
    at java.management/com.sun.jmx.mbeanserver.DefaultMXBeanMappingFactory.mappingForType(DefaultMXBeanMappingFactory.java:261)
    at java.management/com.sun.jmx.mbeanserver.DefaultMXBeanMappingFactory.makeCompositeMapping(DefaultMXBeanMappingFactory.java:473)
    at java.management/com.sun.jmx.mbeanserver.DefaultMXBeanMappingFactory.makeMapping(DefaultMXBeanMappingFactory.java:294)
    at java.management/com.sun.jmx.mbeanserver.DefaultMXBeanMappingFactory.mappingForType(DefaultMXBeanMappingFactory.java:259)
    ... 37 common frames omitted
Caused by: javax.management.openmbean.OpenDataException: Cannot convert type: java.time.temporal.TemporalUnit
    at java.management/com.sun.jmx.mbeanserver.DefaultMXBeanMappingFactory.openDataException(DefaultMXBeanMappingFactory.java:1445)
    at java.management/com.sun.jmx.mbeanserver.DefaultMXBeanMappingFactory.mappingForType(DefaultMXBeanMappingFactory.java:261)
    at java.management/com.sun.jmx.mbeanserver.DefaultMXBeanMappingFactory.makeArrayOrCollectionMapping(DefaultMXBeanMappingFactory.java:319)
    at java.management/com.sun.jmx.mbeanserver.DefaultMXBeanMappingFactory.makeParameterizedTypeMapping(DefaultMXBeanMappingFactory.java:398)
    at java.management/com.sun.jmx.mbeanserver.DefaultMXBeanMappingFactory.makeMapping(DefaultMXBeanMappingFactory.java:297)
    at java.management/com.sun.jmx.mbeanserver.DefaultMXBeanMappingFactory.mappingForType(DefaultMXBeanMappingFactory.java:259)
    ... 40 common frames omitted
Caused by: javax.management.openmbean.OpenDataException: Recursive data structure, including java.time.Duration
    at java.management/com.sun.jmx.mbeanserver.DefaultMXBeanMappingFactory.mappingForType(DefaultMXBeanMappingFactory.java:248)
    at java.management/com.sun.jmx.mbeanserver.DefaultMXBeanMappingFactory.makeCompositeMapping(DefaultMXBeanMappingFactory.java:473)
    at java.management/com.sun.jmx.mbeanserver.DefaultMXBeanMappingFactory.makeMapping(DefaultMXBeanMappingFactory.java:294)
    at java.management/com.sun.jmx.mbeanserver.DefaultMXBeanMappingFactory.mappingForType(DefaultMXBeanMappingFactory.java:259)
    ... 44 common frames omitted

Advertisement

Answer

This issue was happening when we were trying to create a BasicDataSource BasicDataSource dataSource = new BasicDataSource(); which was imported from import org.apache.tomcat.dbcp.dbcp2.BasicDataSource;

So we found a workaround to remove the tomcat dbcp dependency by excluding it from spring-boot starter tomcat and tomcat jdbc.

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-tomcat</artifactId>
    <scope>provided</scope>
    <exclusions>
        <exclusion>
            <groupId>org.apache.tomcat</groupId>
                <artifactId>tomcat-dbcp</artifactId>
        </exclusion>
    </exclusions>
</dependency>

<dependency>
    <groupId>org.apache.tomcat</groupId>
    <artifactId>tomcat-jdbc</artifactId>
</dependency>

and Replacing the datasource to org.apache.tomcat.jdbc.pool.DataSource dataSource = new org.apache.tomcat.jdbc.pool.DataSource();

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement