内容转自:http://blog.csdn.net/hzw2312/article/details/51512393
版本:
Jedis 2.5.2.jar,commons-pool2-2.0.jar
配置文件:
- <bean id="poolConfig" class="redis.clients.jedis.JedisPoolConfig">
- <property name="maxIdle" value="${redis.maxIdle}" />
- <property name="maxActive" value="${redis.maxActive.value}" />
- <property name="maxWait" value="${redis.maxWait}" />
- <property name="testOnBorrow" value="${redis.testOnBorrow}" />
- </bean>
启动报错:
- 严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
- org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'poolConfig' defined in file [E:\Workspaces\eclipse\yfkj\yftms\redis\WebContent\WEB-INF\classes\applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'maxActive' of bean class [redis.clients.jedis.JedisPoolConfig]: Bean property 'maxActive' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
- at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1518)
- at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1226)
- 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:306)
- at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
- at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
- at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
- at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)
- at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839)
- at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)
- at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:444)
- at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:326)
- at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)
- at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5068)
- at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5584)
- at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
- at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1572)
- at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1562)
- at java.util.concurrent.FutureTask.run(Unknown Source)
- at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
- at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
- at java.lang.Thread.run(Unknown Source)
- Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'maxActive' of bean class [redis.clients.jedis.JedisPoolConfig]: Bean property 'maxActive' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
- at org.springframework.beans.BeanWrapperImpl.createNotWritablePropertyException(BeanWrapperImpl.java:231)
- at org.springframework.beans.AbstractNestablePropertyAccessor.setPropertyValue(AbstractNestablePropertyAccessor.java:423)
- at org.springframework.beans.AbstractNestablePropertyAccessor.setPropertyValue(AbstractNestablePropertyAccessor.java:280)
- at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:95)
- at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:75)
- at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1514)
- ... 22 more
原因是:新版本的jedis中将maxActive改成了maxTotal , MaxWait改成了MaxWaitMillis
解决办法:
将改变了的属性替换掉就好:
- <bean id="poolConfig" class="redis.clients.jedis.JedisPoolConfig">
- <property name="maxIdle" value="${redis.maxIdle}" />
- <!-- <property name="maxActive" value="${redis.maxActive.value}" />
- <property name="maxWait" value="${redis.maxWait}" /> -->
- <property name="maxTotal" value="${redis.maxActive.value}" />
- <property name="maxWaitMillis" value="${redis.maxWait}"></property>
- <property name="testOnBorrow" value="${redis.testOnBorrow}" />
- </bean>
这样就能正常启动啦!