org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'redisClusterAction': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jedisCluster' defined in class path resource [redis.xml]: Invocation of init method failed; nested exception is java.lang.NumberFormatException: For input string: "3000@13000"
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:311)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:305)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:301)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:196)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:835)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:537)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:446)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:328)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4727)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5189)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:752)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:728)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
at org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:1702)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:300)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:482)
at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:431)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:300)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1468)
at javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:76)
at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1309)
at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1401)
at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:829)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:324)
at sun.rmi.transport.Transport$1.run(Transport.java:200)
at sun.rmi.transport.Transport$1.run(Transport.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:683)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jedisCluster' defined in class path resource [redis.xml]: Invocation of init method failed; nested exception is java.lang.NumberFormatException: For input string: "3000@13000"
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1578)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:305)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:301)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:201)
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.autowireResource(CommonAnnotationBeanPostProcessor.java:512)
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:486)
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:615)
at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:169)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:308)
... 58 more
Caused by: java.lang.NumberFormatException: For input string: "3000@13000"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:580)
at java.lang.Integer.valueOf(Integer.java:766)
把你的redis.xml贴出来看看,,,好像是你的某个配置文件应该是 Int,你配置成了3000@13000导致报错了。
回复 @丽宝宝:你这个配置没毛病。。。问题不在这里。我在我本地按照你的配置,是可以跑成功的!redis.xml贴出来了,麻烦看看更新jedis到最新版本。
程序和Linux的服务器都需要更新吗redis.xml如下
<?xmlversion="1.0"encoding="UTF-8"?><beansxmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:p="http://www.springframework.org/schema/p"xmlns:context="http://www.springframework.org/schema/context"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-4.2.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-4.2.xsd"><!--连接池配置--><beanname="genericObjectPoolConfig"class="org.apache.commons.pool2.impl.GenericObjectPoolConfig"><propertyname="maxWaitMillis"value="-1"/><propertyname="maxTotal"value="1000"/><propertyname="minIdle"value="8"/><propertyname="maxIdle"value="100"/></bean><beanid="jedisCluster"class="com.redis.util.JedisClusterFactory"><propertyname="addressConfig"><value>classpath:connect-redis.properties</value></property><propertyname="addressKeyPrefix"value="address"/><!--属性文件里key的前缀--><propertyname="timeout"value="300000"/><!--代表集群有几台redis--><propertyname="maxRedirections"value="6"/><propertyname="genericObjectPoolConfig"ref="genericObjectPoolConfig"/></bean></beans>
connect-redis.properties如下
address1=192.168.232.140:1000address2=192.168.232.140:1001address3=192.168.232.140:2000address4=192.168.232.140:2001address5=192.168.232.140:3000address6=192.168.232.140:3001
集群工厂类,执行以下代码时报错
jedisCluster=newJedisCluster(jedisClusterNode,timeout,maxRedirections,genericObjectPoolConfig);
packagecom.redis.util;importorg.apache.commons.pool2.impl.GenericObjectPoolConfig;importorg.springframework.beans.factory.FactoryBean;importorg.springframework.beans.factory.InitializingBean;importorg.springframework.core.io.Resource;importredis.clients.jedis.HostAndPort;importredis.clients.jedis.JedisCluster;importjava.util.HashSet;importjava.util.Properties;importjava.util.Set;importjava.util.regex.Pattern;/***Jedis集群工厂*/publicclassJedisClusterFactoryimplementsInitializingBean,FactoryBean<JedisCluster>{privateResourceaddressConfig;//下面变量对应springredis配置文件中的property的nameprivateJedisClusterjedisCluster;privateStringaddressKeyPrefix;privateIntegertimeout;privateIntegermaxRedirections;privateGenericObjectPoolConfiggenericObjectPoolConfig;//正则表达式匹配ip和portprivatePatternp=Pattern.compile("^.+[:]\\d{1,5}\\s*$");/***实现InitializingBean的接口,初始化的得到jedisCluster*/publicvoidafterPropertiesSet()throwsException{Set<HostAndPort>jedisClusterNode=this.parseHostAndPort();jedisCluster=newJedisCluster(jedisClusterNode,timeout,maxRedirections,genericObjectPoolConfig);System.out.println();}/***实现FactoryBean的接口*获取jedisCluster对象*/publicJedisClustergetObject()throwsException{returnjedisCluster;}/***实现FactoryBean的接口*获取jedisCluster的类型*/publicClass<?extendsJedisCluster>getObjectType(){return(jedisCluster!=null?this.jedisCluster.getClass():JedisCluster.class);}/***实现FactoryBean的接口*/publicbooleanisSingleton(){returntrue;}/***解析Jedis配置文件,看是否满足IP和端口*@return*/privateSet<HostAndPort>parseHostAndPort()throwsException{Set<HostAndPort>hostAndPorts=newHashSet<HostAndPort>();try{Propertiesproperties=newProperties();properties.load(this.addressConfig.getInputStream());for(Objectkey:properties.keySet()){//如果key不是以addressKeyPrefix的值开头,则continueif(!((String)key).startsWith(addressKeyPrefix)){continue;}//根据key从properties中取出值Stringvalus=(String)properties.get(key);//判断取出的value是否是ip和portbooleanisIPProt=p.matcher(valus).matches();if(!isIPProt){thrownewIllegalArgumentException("ip和port不合法!");}String[]ipAndPort=valus.split(":");HostAndPorthostAndPort=newHostAndPort(ipAndPort[0],Integer.parseInt(ipAndPort[1]));hostAndPorts.add(hostAndPort);}}catch(Exceptione){thrownewException("解析jedis配置文件失败!");}returnhostAndPorts;}//set方法publicvoidsetJedisCluster(JedisClusterjedisCluster){this.jedisCluster=jedisCluster;}publicvoidsetAddressKeyPrefix(StringaddressKeyPrefix){this.addressKeyPrefix=addressKeyPrefix;}publicvoidsetTimeout(Integertimeout){this.timeout=timeout;}publicvoidsetMaxRedirections(IntegermaxRedirections){this.maxRedirections=maxRedirections;}publicvoidsetGenericObjectPoolConfig(GenericObjectPoolConfiggenericObjectPoolConfig){this.genericObjectPoolConfig=genericObjectPoolConfig;}publicvoidsetAddressConfig(ResourceaddressConfig){this.addressConfig=addressConfig;}}
搜一下 3000@13000在哪。。。。
这个运行才能有,没办法搜索更新jedis到最新版本。
感谢各位的解答,问题刚刚解决了
/**
*实现InitializingBean的接口,初始化的得到jedisCluster
*/
publicvoidafterPropertiesSet()throwsException{
Set<HostAndPort>jedisClusterNode=this.parseHostAndPort();
if(genericObjectPoolConfig==null){
genericObjectPoolConfig=getGenericObjectPoolConfig();
}
//问题就出现在这里
//旧代码jedisCluster=newJedisCluster(jedisClusterNode,timeout,maxRedirections,genericObjectPoolConfig);
jedisCluster=newJedisCluster(jedisClusterNode,genericObjectPoolConfig); //正确代码
System.out.println();
}
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。