In this paper, a personal blog address: www.leafage.top/posts/detai…

This service uses the spring-boot-starter-data-redis dependency. It reported an error when releasing the test. It was very embarrassing. Why, I’m running fine locally… Is it your routine? 😂).

The error details are as follows:

     6	2021-06-22 09:23:17.291 [application-name] [main] WARN  o.s.b.w.s.c.AnnotationConfigServletWebServerApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'redisConnectionFactory' defined in class path resource [org/springframework/boot/autoconfigure/data/redis/LettuceConnectionConfiguration.class] :Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory]: Factory method 'redisConnectionFactory' threw exception; nested exception is java.lang.NoClassDefFoundError: org/apache/commons/pool2/impl/GenericObjectPoolConfig
     7	2021-06-22 09:23:17.343 [application-name] [main] ERROR o.s.b.SpringApplication - Application run failed
     8	org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'redisConnectionFactory' defined in class path resource [org/springframework/boot/autoconfigure/data/redis/LettuceConnectionConfiguration.class] :Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory]: Factory method 'redisConnectionFactory' threw exception; nested exception is java.lang.NoClassDefFoundError: org/apache/commons/pool2/impl/GenericObjectPoolConfig
     9		at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:657)
    10		at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:637)
    11at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutow ireCapableBeanFactory.java:1341)
    12at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableB eanFactory.java:1181)
    13at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFac tory.java:556)
    14at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFacto ry.java:516)
    15		at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324)
    16		at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
    17		at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322)
    18		at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
    19at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory .java:897)
    20at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContex t.java:879)
    21		at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:551)
    22at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationConte xt.java:143)
    23		at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758)
    24		at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750)
    25		at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:405)
    26		at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
    27		at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237)
    28		at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
    29		at com.ichinae.imis.MgrApplication.main(MgrApplication.java:20)
    30		at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    31		at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    32		at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    33		at java.lang.reflect.Method.invoke(Method.java:498)
    34		at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49)
    35		at org.springframework.boot.loader.Launcher.launch(Launcher.java:107)
    36		at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
    37		at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:88)
    38	Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory]: Factory method 'redisConnectionFactory' threw exception; nested exception is java.lang.NoClassDefFoundError: org/apache/commons/pool2/impl/GenericObjectPoolConfig
    39		at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
    40		at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:652)
    41.28 common frames omitted
    42	Caused by: java.lang.NoClassDefFoundError: org/apache/commons/pool2/impl/GenericObjectPoolConfig
    43at org.springframework.data.redis.connection.lettuce.LettucePoolingClientConfiguration$LettucePoolingClientConfigurationBui lder.<init>(LettucePoolingClientConfiguration.java:94)
    44at org.springframework.data.redis.connection.lettuce.LettucePoolingClientConfiguration.builder(LettucePoolingClientConfigur ation.java:51)
    45at org.springframework.boot.autoconfigure.data.redis.LettuceConnectionConfiguration$PoolBuilderFactory.createBuilder(Lettuc eConnectionConfiguration.java:159)
    46at org.springframework.boot.autoconfigure.data.redis.LettuceConnectionConfiguration.createBuilder(LettuceConnectionConfigur ation.java:107)
    47at org.springframework.boot.autoconfigure.data.redis.LettuceConnectionConfiguration.getLettuceClientConfiguration(LettuceCo nnectionConfiguration.java:92)
    48at org.springframework.boot.autoconfigure.data.redis.LettuceConnectionConfiguration.redisConnectionFactory(LettuceConnectio nConfiguration.java:74)
    49		at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    50		at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    51		at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    52		at java.lang.reflect.Method.invoke(Method.java:498)
    53		at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
    54.29 common frames omitted
    55	Caused by: java.lang.ClassNotFoundException: org.apache.commons.pool2.impl.GenericObjectPoolConfig
    56		at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    57		at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    58		at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:151)
    59		at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    60.40 common frames omitted
Copy the code

As usual, copy exception information, paste a Google search, and then introduce all the prices to apache Common Pool2 dependency, and then there is actually said to rebuild a project into… (brother you funny of 🙄).

Note the cause of this exception and check if your configuration file has an odb.pool configuration. If so, there are two ways to solve the problem:

  1. Add a dependency to common-pool2 because the loader cannot find the relevant class at startup:
<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-pool2</artifactId>
</dependency>
Copy the code
  1. Remove the weir. pool configuration. If you don’t need any of it, or if it’s copied from the database, use the default.