Mr Smith
Mr Smith

Reputation: 3486

Class org.apache.commons.pool2.impl.BaseObjectPoolConfig does not have member field 'java.time.Duration DEFAULT_DURATION_BETWEEN_EVICTION_RUNS

I'm trying to run a Java 21 app with Spring boot 2.7.18 and mybatis 3.5.10. The project compiles fine but I get the exception below when i run it. The DEFAULT_DURATION_BETWEEN_EVICTION_RUNS property is not missing, its private.

I have another project with a similar set up that runs fine. Seems like we have a wrong config setting or missing/extra dependency in the project that is failing, but im not sure what at the moment.

Any suggestions?

 Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.commons.dbcp2.BasicDataSource]: Constructor threw exception; nested exception is java.lang.NoSuchFieldError: Class org.apache.commons.pool2.impl.BaseObjectPoolConfig does not have member field 'java.time.Duration DEFAULT_DURATION_BETWEEN_EVICTION_RUNS'
        at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:226)
        at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:148)
        at org.springframework.boot.jdbc.DataSourceBuilder.build(DataSourceBuilder.java:175)
        at com.test.domain.configuration.Db2Configuration.dbDataSource(Db2Configuration.java:29)
        at com.test.domain.configuration.Db2Configuration$$EnhancerBySpringCGLIB$$4161f1f4.CGLIB$dbDataSource$1(<generated>)
        at com.test.domain.configuration.Db2Configuration$$EnhancerBySpringCGLIB$$4161f1f4$$FastClassBySpringCGLIB$$c5edc613.invoke(<generated>)
        at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244)
        at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:331)
        at com.test.domain.configuration.Db2Configuration$$EnhancerBySpringCGLIB$$4161f1f4.dbDataSource(<generated>)
        at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
        at java.base/java.lang.reflect.Method.invoke(Method.java:580)
        at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
        ... 107 more
    Caused by: java.lang.NoSuchFieldError: Class org.apache.commons.pool2.impl.BaseObjectPoolConfig does not have member field 'java.time.Duration DEFAULT_DURATION_BETWEEN_EVICTION_RUNS'
        at org.apache.commons.dbcp2.BasicDataSource.<init>(BasicDataSource.java:260)
        at java.base/jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java:62)
        at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:502)
        at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:486)
        at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:213)

Upvotes: 0

Views: 346

Answers (1)

Mr Smith
Mr Smith

Reputation: 3486

I was missing this dependency. I added this & the error disappeared

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-jdbc</artifactId>
     </dependency>

Upvotes: 0

Related Questions