Home  >  Forum  >  Spring
Post New Query

javax.management.InstanceNotFoundException: org.apache.commons.dbcp2:name=getDataSource, type=BasicDataSource



Asked on July 28, 2019
I am creating Spring Boot Batch + MySQL + DBCP2 application getting following error. How to fix it.

2019-07-29 08:28:53.408  WARN 3648 --- [       Thread-1] o.apache.commons.dbcp2.BasicDataSource   : Failed to unregister the JMX name: org.apache.commons.dbcp2:name=getDataSource,type=BasicDataSource

javax.management.InstanceNotFoundException: org.apache.commons.dbcp2:name=getDataSource,type=BasicDataSource
at java.management/com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.getMBean(DefaultMBeanServerInterceptor.java:1083) ~[na:na]
at java.management/com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.exclusiveUnregisterMBean(DefaultMBeanServerInterceptor.java:423) ~[na:na]
at java.management/com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.unregisterMBean(DefaultMBeanServerInterceptor.java:411) ~[na:na]
at java.management/com.sun.jmx.mbeanserver.JmxMBeanServer.unregisterMBean(JmxMBeanServer.java:546) ~[na:na]
at org.apache.commons.dbcp2.BasicDataSource.close(BasicDataSource.java:1917) ~[commons-dbcp2-2.1.1.jar:2.1.1]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
at org.springframework.beans.factory.support.DisposableBeanAdapter.invokeCustomDestroyMethod(DisposableBeanAdapter.java:339) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.beans.factory.support.DisposableBeanAdapter.destroy(DisposableBeanAdapter.java:273) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroyBean(DefaultSingletonBeanRegistry.java:571) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingleton(DefaultSingletonBeanRegistry.java:543) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingleton(DefaultListableBeanFactory.java:1036) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingletons(DefaultSingletonBeanRegistry.java:504) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingletons(DefaultListableBeanFactory.java:1029) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:1057) ~[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1026) ~[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.context.support.AbstractApplicationContext$1.run(AbstractApplicationContext.java:945) ~[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE]




Replied on July 28, 2019
You are getting error because BasicDataSource is already closed and MBean is trying to unregister it on application shutdown. BasicDataSource is registered as MBean and all registered Mbean are unregistered and closed on application shutdown. BasicDataSource is closed already by itself using its default close() method because BasicDataSource implements AutoCloseable.

We have following solutions to fix the error.

1. Configure destroyMethod in configuration file. 

@Bean(destroyMethod = "")
public DataSource getDataSource() {
------
}

2. Use another connection pool such as HikariCP.

Reference




Replied on July 28, 2019
Thanks. Working.

Write Answer








©2019 concretepage.com | Privacy Policy | Contact Us