jedis icon indicating copy to clipboard operation
jedis copied to clipboard

Unable to register MBean

Open pinyht opened this issue 2 years ago • 20 comments

When I use Jedis 4.0.0 in Springboot, it can't start, in jedis 3.7.1 is OK

Redis / Jedis Configuration

there is my config file

@Configuration @Slf4j public class RedisConfig { @Value("${spring.redis.host:}") private String host;

@Value("${spring.redis.port:0}")
private int port;

@Value("${spring.redis.password:}")
private String password;

@Value("${spring.redis.database:0}")
private int database;

@Value("${spring.redis.jedis.pool.max-active:0}")
private int maxActive;

@Value("${spring.redis.jedis.pool.max-idle:0}")
private int maxIdle;

@Value("${spring.redis.timeout:0}")
private int timeout;

@Bean
public JedisPool jedisPool() {
    JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
    jedisPoolConfig.setMaxTotal(maxActive);
    jedisPoolConfig.setMaxIdle(maxIdle);
    jedisPoolConfig.setMaxWait(Duration.ofMillis(timeout));
    JedisPool pool = new JedisPool(jedisPoolConfig, host, port, timeout, password, database);
    return pool;
}

}

error log

org.springframework.jmx.export.UnableToRegisterMBeanException: Unable to register MBean [JedisPool [maxTotal=100, blockWhenExhausted=true, maxWaitDuration=PT20S, lifo=true, fairness=false, testOnCreate=false, testOnBorrow=false, testOnReturn=false, testWhileIdle=true, durationBetweenEvictionRuns=PT30S, numTestsPerEvictionRun=-1, minEvictableIdleTimeDuration=PT1M, softMinEvictableIdleTimeDuration=PT-0.001S, evictionPolicy=org.apache.commons.pool2.impl.DefaultEvictionPolicy@11c7a0b4, closeLock=java.lang.Object@75ed125a, closed=false, evictionLock=java.lang.Object@653a5967, evictor=org.apache.commons.pool2.impl.BaseGenericObjectPool$Evictor@5a85b4e6, evictionIterator=null, factoryClassLoader=java.lang.ref.WeakReference@766b6d02, oname=org.apache.commons.pool2:type=GenericObjectPool,name=pool, creationStackTrace=java.lang.Exception at org.apache.commons.pool2.impl.BaseGenericObjectPool.(BaseGenericObjectPool.java:407) at org.apache.commons.pool2.impl.GenericObjectPool.(GenericObjectPool.java:147) at redis.clients.jedis.util.Pool.(Pool.java:16) at redis.clients.jedis.util.Pool.(Pool.java:12) at redis.clients.jedis.JedisPool.(JedisPool.java:359) at redis.clients.jedis.JedisPool.(JedisPool.java:278) at redis.clients.jedis.JedisPool.(JedisPool.java:188) at redis.clients.jedis.JedisPool.(JedisPool.java:160) at com.eashung.xiaodu.infrastructure.redis.config.RedisConfig.jedisPool(RedisConfig.java:72) at com.eashung.xiaodu.infrastructure.redis.config.RedisConfig$$EnhancerBySpringCGLIB$$5519e373.CGLIB$jedisPool$0() at com.eashung.xiaodu.infrastructure.redis.config.RedisConfig$$EnhancerBySpringCGLIB$$5519e373$$FastClassBySpringCGLIB$$bab84c1c.invoke() at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244) at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:331) at com.eashung.xiaodu.infrastructure.redis.config.RedisConfig$$EnhancerBySpringCGLIB$$5519e373.jedisPool() 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.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653) at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:486) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1352) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1195) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276) at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1389) at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1309) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:656) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:639) at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:119) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:399) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1431) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:619) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:953) 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:730) at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:412) at org.springframework.boot.SpringApplication.run(SpringApplication.java:302) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1301) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1290) at com.eashung.xiaodu.application.chat.ApplicationChatApplication.main(ApplicationChatApplication.java:15) , borrowedCount=0, returnedCount=0, createdCount=0, destroyedCount=0, destroyedByEvictorCount=0, destroyedByBorrowValidationCount=0, activeTimes=StatsStore [[]], size=100, index=0], idleTimes=StatsStore [[]], size=100, index=0], waitTimes=StatsStore [[]], size=100, index=0], maxBorrowWaitDuration=PT0S, swallowedExceptionListener=null, factoryType=null, maxIdle=10, minIdle=0, factory=redis.clients.jedis.JedisFactory@6b09ce57, allObjects={}, createCount=0, idleObjects=[], abandonedConfig=null]] with key 'jedisPool'; nested exception is javax.management.InstanceAlreadyExistsException: MXBean already registered with name org.apache.commons.pool2:type=GenericObjectPool,name=pool at org.springframework.jmx.export.MBeanExporter.registerBeanNameOrInstance(MBeanExporter.java:626) ~[spring-context-5.3.14.jar:5.3.14] at org.springframework.jmx.export.MBeanExporter.lambda$registerBeans$2(MBeanExporter.java:552) ~[spring-context-5.3.14.jar:5.3.14] at java.base/java.util.HashMap.forEach(HashMap.java:1336) ~[na:na] at org.springframework.jmx.export.MBeanExporter.registerBeans(MBeanExporter.java:552) ~[spring-context-5.3.14.jar:5.3.14] at org.springframework.jmx.export.MBeanExporter.afterSingletonsInstantiated(MBeanExporter.java:435) ~[spring-context-5.3.14.jar:5.3.14] at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:972) ~[spring-beans-5.3.14.jar:5.3.14] at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918) ~[spring-context-5.3.14.jar:5.3.14] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[spring-context-5.3.14.jar:5.3.14] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145) ~[spring-boot-2.6.2.jar:2.6.2] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:730) ~[spring-boot-2.6.2.jar:2.6.2] at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:412) ~[spring-boot-2.6.2.jar:2.6.2] at org.springframework.boot.SpringApplication.run(SpringApplication.java:302) ~[spring-boot-2.6.2.jar:2.6.2] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1301) ~[spring-boot-2.6.2.jar:2.6.2] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1290) ~[spring-boot-2.6.2.jar:2.6.2] at com.eashung.xiaodu.application.chat.ApplicationChatApplication.main(ApplicationChatApplication.java:15) ~[classes/:na] Caused by: javax.management.InstanceAlreadyExistsException: MXBean already registered with name org.apache.commons.pool2:type=GenericObjectPool,name=pool at java.management/com.sun.jmx.mbeanserver.MXBeanLookup.addReference(MXBeanLookup.java:151) ~[na:na] at java.management/com.sun.jmx.mbeanserver.MXBeanSupport.register(MXBeanSupport.java:160) ~[na:na] at java.management/com.sun.jmx.mbeanserver.MBeanSupport.preRegister2(MBeanSupport.java:173) ~[na:na] at java.management/com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerDynamicMBean(DefaultMBeanServerInterceptor.java:919) ~[na:na] at java.management/com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerObject(DefaultMBeanServerInterceptor.java:890) ~[na:na] at java.management/com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerMBean(DefaultMBeanServerInterceptor.java:320) ~[na:na] at java.management/com.sun.jmx.mbeanserver.JmxMBeanServer.registerMBean(JmxMBeanServer.java:522) ~[na:na] at org.springframework.jmx.support.MBeanRegistrationSupport.doRegister(MBeanRegistrationSupport.java:138) ~[spring-context-5.3.14.jar:5.3.14] at org.springframework.jmx.export.MBeanExporter.registerBeanInstance(MBeanExporter.java:672) ~[spring-context-5.3.14.jar:5.3.14] at org.springframework.jmx.export.MBeanExporter.registerBeanNameOrInstance(MBeanExporter.java:616) ~[spring-context-5.3.14.jar:5.3.14] ... 14 common frames omitted

Jedis version:

4.0.0

Redis version:

6.2.5

Java version:

11.0.9.1

Spring Boot version:

2.6.2

pinyht avatar Dec 28 '21 10:12 pinyht

@pinyht Please check javax.management.InstanceAlreadyExistsException: MXBean already registered with name org.apache.commons.pool2:type=GenericObjectPool,name=pool

sazzad16 avatar Dec 28 '21 11:12 sazzad16

I have try to use "jedisPoolConfig.setJmxNamePrefix("jedis")" ,but it can't start too, the log changes to: javax.management.InstanceAlreadyExistsException: MXBean already registered with name org.apache.commons.pool2:type=GenericObjectPool,name=jedis

pinyht avatar Dec 28 '21 13:12 pinyht

after my debug, I noticed the jedisPool bean has register twice in com.sun.jmx.mbeanserver.register method, I don't know why

pinyht avatar Dec 28 '21 15:12 pinyht

@pinyht Can you set a breakpoint in org.apache.commons.pool2.impl.BaseGenericObjectPool#jmxRegister? And debug to see if there will be two calls to here? If so, what is their stack?

yangbodong22011 avatar Dec 29 '21 02:12 yangbodong22011

@yangbodong22011 yes, in org.apache.commons.pool2.impl.BaseGenericObjectPool#jmxRegister has call twice

first time: image

jmxRegister:1196, BaseGenericObjectPool (org.apache.commons.pool2.impl) :401, BaseGenericObjectPool (org.apache.commons.pool2.impl) :147, GenericObjectPool (org.apache.commons.pool2.impl) :16, Pool (redis.clients.jedis.util) :12, Pool (redis.clients.jedis.util) :359, JedisPool (redis.clients.jedis) :278, JedisPool (redis.clients.jedis) :188, JedisPool (redis.clients.jedis) :160, JedisPool (redis.clients.jedis) jedisPool:66, RedisConfig (com.eashung.xiaodu.infrastructure.redis.config) CGLIB$jedisPool$0:-1, RedisConfig$$EnhancerBySpringCGLIB$$69011b04 (com.eashung.xiaodu.infrastructure.redis.config) invoke:-1, RedisConfig$$EnhancerBySpringCGLIB$$69011b04$$FastClassBySpringCGLIB$$f3f5dda3 (com.eashung.xiaodu.infrastructure.redis.config) invokeSuper:244, MethodProxy (org.springframework.cglib.proxy) intercept:331, ConfigurationClassEnhancer$BeanMethodInterceptor (org.springframework.context.annotation) jedisPool:-1, RedisConfig$$EnhancerBySpringCGLIB$$69011b04 (com.eashung.xiaodu.infrastructure.redis.config) invoke0:-1, NativeMethodAccessorImpl (jdk.internal.reflect) invoke:62, NativeMethodAccessorImpl (jdk.internal.reflect) invoke:43, DelegatingMethodAccessorImpl (jdk.internal.reflect) invoke:566, Method (java.lang.reflect) instantiate:154, SimpleInstantiationStrategy (org.springframework.beans.factory.support) instantiate:653, ConstructorResolver (org.springframework.beans.factory.support) instantiateUsingFactoryMethod:486, ConstructorResolver (org.springframework.beans.factory.support) instantiateUsingFactoryMethod:1352, AbstractAutowireCapableBeanFactory (org.springframework.beans.factory.support) createBeanInstance:1195, AbstractAutowireCapableBeanFactory (org.springframework.beans.factory.support) doCreateBean:582, AbstractAutowireCapableBeanFactory (org.springframework.beans.factory.support) createBean:542, AbstractAutowireCapableBeanFactory (org.springframework.beans.factory.support) lambda$doGetBean$0:335, AbstractBeanFactory (org.springframework.beans.factory.support) getObject:-1, 667890001 (org.springframework.beans.factory.support.AbstractBeanFactory$$Lambda$310) getSingleton:234, DefaultSingletonBeanRegistry (org.springframework.beans.factory.support) doGetBean:333, AbstractBeanFactory (org.springframework.beans.factory.support) getBean:208, AbstractBeanFactory (org.springframework.beans.factory.support) resolveCandidate:276, DependencyDescriptor (org.springframework.beans.factory.config) doResolveDependency:1389, DefaultListableBeanFactory (org.springframework.beans.factory.support) resolveDependency:1309, DefaultListableBeanFactory (org.springframework.beans.factory.support) resolveFieldValue:656, AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement (org.springframework.beans.factory.annotation) inject:639, AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement (org.springframework.beans.factory.annotation) inject:119, InjectionMetadata (org.springframework.beans.factory.annotation) postProcessProperties:399, AutowiredAnnotationBeanPostProcessor (org.springframework.beans.factory.annotation) populateBean:1431, AbstractAutowireCapableBeanFactory (org.springframework.beans.factory.support) doCreateBean:619, AbstractAutowireCapableBeanFactory (org.springframework.beans.factory.support) createBean:542, AbstractAutowireCapableBeanFactory (org.springframework.beans.factory.support) lambda$doGetBean$0:335, AbstractBeanFactory (org.springframework.beans.factory.support) getObject:-1, 667890001 (org.springframework.beans.factory.support.AbstractBeanFactory$$Lambda$310) getSingleton:234, DefaultSingletonBeanRegistry (org.springframework.beans.factory.support) doGetBean:333, AbstractBeanFactory (org.springframework.beans.factory.support) getBean:208, AbstractBeanFactory (org.springframework.beans.factory.support) preInstantiateSingletons:953, DefaultListableBeanFactory (org.springframework.beans.factory.support) finishBeanFactoryInitialization:918, AbstractApplicationContext (org.springframework.context.support) refresh:583, AbstractApplicationContext (org.springframework.context.support) refresh:145, ServletWebServerApplicationContext (org.springframework.boot.web.servlet.context) refresh:730, SpringApplication (org.springframework.boot) refreshContext:412, SpringApplication (org.springframework.boot) run:302, SpringApplication (org.springframework.boot) run:1301, SpringApplication (org.springframework.boot) run:1290, SpringApplication (org.springframework.boot) main:15, ApplicationChatApplication (com.eashung.xiaodu.application.chat)

second time: image jmxRegister:1196, BaseGenericObjectPool (org.apache.commons.pool2.impl) :401, BaseGenericObjectPool (org.apache.commons.pool2.impl) :147, GenericObjectPool (org.apache.commons.pool2.impl) :16, Pool (redis.clients.jedis.util) :12, Pool (redis.clients.jedis.util) :359, JedisPool (redis.clients.jedis) :278, JedisPool (redis.clients.jedis) :188, JedisPool (redis.clients.jedis) :160, JedisPool (redis.clients.jedis) jedisPool:66, RedisConfig (com.eashung.xiaodu.infrastructure.redis.config) CGLIB$jedisPool$0:-1, RedisConfig$$EnhancerBySpringCGLIB$$69011b04 (com.eashung.xiaodu.infrastructure.redis.config) invoke:-1, RedisConfig$$EnhancerBySpringCGLIB$$69011b04$$FastClassBySpringCGLIB$$f3f5dda3 (com.eashung.xiaodu.infrastructure.redis.config) invokeSuper:244, MethodProxy (org.springframework.cglib.proxy) intercept:331, ConfigurationClassEnhancer$BeanMethodInterceptor (org.springframework.context.annotation) jedisPool:-1, RedisConfig$$EnhancerBySpringCGLIB$$69011b04 (com.eashung.xiaodu.infrastructure.redis.config) invoke0:-1, NativeMethodAccessorImpl (jdk.internal.reflect) invoke:62, NativeMethodAccessorImpl (jdk.internal.reflect) invoke:43, DelegatingMethodAccessorImpl (jdk.internal.reflect) invoke:566, Method (java.lang.reflect) instantiate:154, SimpleInstantiationStrategy (org.springframework.beans.factory.support) instantiate:653, ConstructorResolver (org.springframework.beans.factory.support) instantiateUsingFactoryMethod:486, ConstructorResolver (org.springframework.beans.factory.support) instantiateUsingFactoryMethod:1352, AbstractAutowireCapableBeanFactory (org.springframework.beans.factory.support) createBeanInstance:1195, AbstractAutowireCapableBeanFactory (org.springframework.beans.factory.support) doCreateBean:582, AbstractAutowireCapableBeanFactory (org.springframework.beans.factory.support) createBean:542, AbstractAutowireCapableBeanFactory (org.springframework.beans.factory.support) lambda$doGetBean$0:335, AbstractBeanFactory (org.springframework.beans.factory.support) getObject:-1, 667890001 (org.springframework.beans.factory.support.AbstractBeanFactory$$Lambda$310) getSingleton:234, DefaultSingletonBeanRegistry (org.springframework.beans.factory.support) doGetBean:333, AbstractBeanFactory (org.springframework.beans.factory.support) getBean:208, AbstractBeanFactory (org.springframework.beans.factory.support) resolveCandidate:276, DependencyDescriptor (org.springframework.beans.factory.config) doResolveDependency:1389, DefaultListableBeanFactory (org.springframework.beans.factory.support) resolveDependency:1309, DefaultListableBeanFactory (org.springframework.beans.factory.support) resolveFieldValue:656, AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement (org.springframework.beans.factory.annotation) inject:639, AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement (org.springframework.beans.factory.annotation) inject:119, InjectionMetadata (org.springframework.beans.factory.annotation) postProcessProperties:399, AutowiredAnnotationBeanPostProcessor (org.springframework.beans.factory.annotation) populateBean:1431, AbstractAutowireCapableBeanFactory (org.springframework.beans.factory.support) doCreateBean:619, AbstractAutowireCapableBeanFactory (org.springframework.beans.factory.support) createBean:542, AbstractAutowireCapableBeanFactory (org.springframework.beans.factory.support) lambda$doGetBean$0:335, AbstractBeanFactory (org.springframework.beans.factory.support) getObject:-1, 667890001 (org.springframework.beans.factory.support.AbstractBeanFactory$$Lambda$310) getSingleton:234, DefaultSingletonBeanRegistry (org.springframework.beans.factory.support) doGetBean:333, AbstractBeanFactory (org.springframework.beans.factory.support) getBean:208, AbstractBeanFactory (org.springframework.beans.factory.support) preInstantiateSingletons:953, DefaultListableBeanFactory (org.springframework.beans.factory.support) finishBeanFactoryInitialization:918, AbstractApplicationContext (org.springframework.context.support) refresh:583, AbstractApplicationContext (org.springframework.context.support) refresh:145, ServletWebServerApplicationContext (org.springframework.boot.web.servlet.context) refresh:730, SpringApplication (org.springframework.boot) refreshContext:412, SpringApplication (org.springframework.boot) run:302, SpringApplication (org.springframework.boot) run:1301, SpringApplication (org.springframework.boot) run:1290, SpringApplication (org.springframework.boot) main:15, ApplicationChatApplication (com.eashung.xiaodu.application.chat)

pinyht avatar Dec 29 '21 02:12 pinyht

  1. Will you initialize two JedisPool objects, otherwise jmxRegister will not be called twice

  2. I noticed that the variable registered is true for the second time, and i = 1. This is a bit confusing to me, because when i = 1, registered should be false image

yangbodong22011 avatar Dec 29 '21 03:12 yangbodong22011

@yangbodong22011 no,I just have one config,can you test in same jedis version and springboot version? when I used jedis 3.7.1,it's OK with the same config file

pinyht avatar Dec 29 '21 04:12 pinyht

Can refer to: https://blog.csdn.net/yiifaa/article/details/73243598

@pinyht

zeekling avatar Dec 29 '21 14:12 zeekling

@zeekling yes, I have read this article,but disable jmx is not a normal choice, I think jedis 4.0.0 have some bug, because I used jedis 3.7.1 with same springboot version and same config class, it can be started normal

pinyht avatar Dec 30 '21 01:12 pinyht

@sazzad16 Did you find out what the cause is? I don't know if you have time to check it out

pinyht avatar Jan 06 '22 01:01 pinyht

@pinyht No, I didn't.

sazzad16 avatar Jan 06 '22 03:01 sazzad16

I get the same spring exception. For now I will keep on using Jedis 3.7.1 because that doesn't have the issue indeed. Would be nice if this could be fixed in a future version!

SimonedeGijt avatar Jan 12 '22 12:01 SimonedeGijt

I get the same spring exception. For now I will keep on using Jedis 3.7.1 because that doesn't have the issue indeed. Would be nice if this could be fixed in a future version!

Can you provide detailed code?

zeekling avatar Jan 15 '22 12:01 zeekling

Hey @zeekling, there is no specific code failing. It is a compile error right. But it seems to have something to do with incompatibility with spring-data.

SimonedeGijt avatar Jan 21 '22 12:01 SimonedeGijt

@SimonedeGijt @pinyht can you provide a barebones example project where this error occurs so that it is reproducible for maintainers?

Akaame avatar Feb 01 '22 18:02 Akaame

Spring Boot 2.6.2 Jedis 4.0.0 and 4.1.1 Java 11.0.11

https://github.com/Akaame/Jedis-2781-Demo

Boots up without JMX registration error.

Please share a minimal reproducible example for your problem.

Akaame avatar Feb 01 '22 19:02 Akaame

I don't really have time for full minimal example, but for me the registration happened in two places due to spring mbean autodetection mechanism:

  • Spring does it in org.springframework.jmx.export.MBeanExporter#registerBeans (using org.springframework.jmx.support.JmxUtils#isMBean for detecting candidates)
  • Jedis does it in constructor of JedisPool through BaseGenericObjectPool.

Solutions I see:

  • disable jmx in JedisPoolConfig and let bean be registered by spring.
JedisPoolConfig config = new JedisPoolConfig();
config.setJmxEnabled(false)
...
  • exclude bean from MBeanExporter and stick to constructor registration. For example:
@Autowired(required = false)
void disableAutoJmxRegistration(MBeanExporter mBeanExporter) {
    mBeanExporter.addExcludedBean(JEDIS_POOL_BEAN_NAME);
}

el-dot avatar Feb 08 '22 13:02 el-dot

image @Akaame I use your demo, it is error too Spring Boot 2.6.2 Jedis 4.0.0 Java 11.0.9.1

pinyht avatar Feb 10 '22 01:02 pinyht

Encountered the same on our local setup. Seems to be working on prod deployments for some reason. Didn't really investigate it further.

Spring Boot 2.6.2, Jedis 4.1.1, OpenJDK 17.0.2. following el-dot's instruction (setJmxEnabled(false)) helped.

DeeVeX avatar Mar 03 '22 15:03 DeeVeX

As @el-dot said ( https://github.com/redis/jedis/issues/2781#issuecomment-1032632503 ):

If you register JedisPoolConfig or some other class extends BaseGenericObjectPool or it's subclass GenericObjectPoolConfig ( which in apache commons pool ) instances to spring . this problem will happen 。becase the same instance registered to jmx twice . And you can use "config.setJmxEnabled(false)' to stop GenericObjectPoolConfig to register to jmx , and then only spring will register this bean to jmx .you can find the registered jmx bean though jmc (locate in jdk).

you can see invoke logic in those class:

  • MBeanExporter class in spring-context-{version}.jar
  • org.springframework.jmx.support.JmxUtils

	public static boolean isMBean(@Nullable Class<?> clazz) {
		return (clazz != null &&
				(DynamicMBean.class.isAssignableFrom(clazz) ||
						(getMBeanInterface(clazz) != null || getMXBeanInterface(clazz) != null)));

  • javax.management.JMX
public static boolean isMXBeanInterface(Class<?> interfaceClass) {
        if (!interfaceClass.isInterface())
            return false;
        if (!Modifier.isPublic(interfaceClass.getModifiers()) &&
            !Introspector.ALLOW_NONPUBLIC_MBEAN) {
            return false;
        }
        MXBean a = interfaceClass.getAnnotation(MXBean.class);
        if (a != null)
            return a.value();
        return interfaceClass.getName().endsWith("MXBean");
        // We don't bother excluding the case where the name is
        // exactly the string "MXBean" since that would mean there
        // was no package name, which is pretty unlikely in practice.
    }

Yeah . Actually the "return interfaceClass.getName().endsWith("MXBean");“ logic works when use apache commons pool .

huayaoyue6 avatar Apr 08 '22 11:04 huayaoyue6