Here we will see a how to fix below exceptions related to Spring Data Redis.
- java.lang.NoClassDefFoundError: org/apache/commons/pool2/impl/GenericObjectPoolConfig exception
- Type redis/clients/jedis/JedisPoolConfig (current frame, stack[1]) is not assignable to org/apache/commons/pool2/impl/GenericObjectPoolConfig.
You might get those issue while working with Spring Data Redis. If you try to use Spring Data Redis with Spring Boot 2.2.6.RELEASE or any other version you might get this issue.
Let’s first replicate this issue. Defined below dependency in pom.xml and after running main class we will have java.lang.NoClassDefFoundError: org/apache/commons/pool2/impl/GenericObjectPoolConfig exception
.
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.6.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis-reactive</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
. ____ _ __ _ _
/\\ / ___’_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | ‘_ | ‘_| | ‘_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
‘ |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.2.6.RELEASE)
2020-05-04 00:28:00.434 INFO 8096 — [ main] com.javatute.SpringMain : Starting SpringMain on anjali-PC with PID 8096 (C:\Users\anjali\Desktop\sprin_hibernate logo\redis\redis\target\classes started by anjali in C:\Users\anjali\Desktop\sprin_hibernate logo\redis\redis)
2020-05-04 00:28:00.434 INFO 8096 — [ main] com.javatute.SpringMain : No active profile set, falling back to default profiles: default
2020-05-04 00:28:01.247 INFO 8096 — [ main] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode!
2020-05-04 00:28:01.262 INFO 8096 — [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data Redis repositories in DEFAULT mode.
2020-05-04 00:28:01.293 INFO 8096 — [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 18ms. Found 0 Redis repository interfaces.
2020-05-04 00:28:01.513 ERROR 8096 — [ main] o.s.boot.SpringApplication : Application run failed
java.lang.NoClassDefFoundError: org/apache/commons/pool2/impl/GenericObjectPoolConfig
at java.lang.Class.getDeclaredConstructors0(Native Method) ~[na:1.8.0_131]
at java.lang.Class.privateGetDeclaredConstructors(Unknown Source) ~[na:1.8.0_131]
at java.lang.Class.getDeclaredConstructors(Unknown Source) ~[na:1.8.0_131]
at org.springframework.boot.context.properties.ConfigurationPropertiesBindConstructorProvider.findConstructorBindingAnnotatedConstructor(ConfigurationPropertiesBindConstructorProvider.java:62) ~[spring-boot-2.2.6.RELEASE.jar:2.2.6.RELEASE]
at org.springframework.boot.context.properties.ConfigurationPropertiesBindConstructorProvider.getBindConstructor(ConfigurationPropertiesBindConstructorProvider.java:48) ~[spring-boot-2.2.6.RELEASE.jar:2.2.6.RELEASE]
at org.springframework.boot.context.properties.ConfigurationPropertiesBean$BindMethod.forType(ConfigurationPropertiesBean.java:311) ~[spring-boot-2.2.6.RELEASE.jar:2.2.6.RELEASE]
at org.springframework.boot.context.properties.ConfigurationPropertiesBeanDefinitionValidator.validate(ConfigurationPropertiesBeanDefinitionValidator.java:63) ~[spring-boot-2.2.6.RELEASE.jar:2.2.6.RELEASE]
at org.springframework.boot.context.properties.ConfigurationPropertiesBeanDefinitionValidator.postProcessBeanFactory(ConfigurationPropertiesBeanDefinitionValidator.java:45) ~[spring-boot-2.2.6.RELEASE.jar:2.2.6.RELEASE]
Another exception.
java.lang.VerifyError: Bad type on operand stack
Exception Details:
Location:
org/springframework/data/redis/connection/jedis/JedisConnectionFactory.<init>(Lorg/springframework/data/redis/connection/RedisClusterConfiguration;Lredis/clients/jedis/JedisPoolConfig;)V @43: invokestatic
Reason:
Type redis/clients/jedis/JedisPoolConfig (current frame, stack[1]) is not assignable to org/apache/commons/pool2/impl/GenericObjectPoolConfig
Current Frame:
bci: @43
flags: { }
locals: { ‘org/springframework/data/redis/connection/jedis/JedisConnectionFactory’, ‘org/springframework/data/redis/connection/RedisClusterConfiguration’, ‘redis/clients/jedis/JedisPoolConfig’ }
stack: { ‘org/springframework/data/redis/connection/jedis/JedisConnectionFactory’, ‘redis/clients/jedis/JedisPoolConfig’ }
Bytecode:
0x0000000: 2ab7 0004 2a03 b500 052a 04b5 0006 2abb
0x0000010: 0007 5912 0811 18eb b700 0ab5 000b 2b12
0x0000020: 19b8 000d 2a2b b500 142a 2cb8 0017 b500
How to fix this error.
Add below dependency in pom.xml.
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
</dependency>
Final working pom.
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.2.6.RELEASE</version> <relativePath /> <!-- lookup parent from repository --> </parent> <groupId>com.javatute</groupId> <artifactId>redis</artifactId> <version>0.0.1-SNAPSHOT</version> <name>redis</name> <description>Demo project for Spring Boot</description> <properties> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis-reactive</artifactId> </dependency> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-pool2</artifactId> </dependency> <dependency> <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> <exclusions> <exclusion> <groupId>org.junit.vintage</groupId> <artifactId>junit-vintage-engine</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>io.projectreactor</groupId> <artifactId>reactor-test</artifactId> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
You may like.
- JPA Cascade Types example using Spring Boot.
- JPA EntityManager persist() and merge() method.
- @ElementCollection Example in Hibernate/JPA Using Spring Boot.
- Hibernate First Level Cache example using Spring Boot.
Spring Data Redis docs.
That’s all we have java.lang.NoClassDefFoundError: org/apache/commons/pool2/impl/GenericObjectPoolConfig.