让Spring Session不再执行config命令
最近由于拼多多强制要求服务商必须入拼多多云,不上就给你应用给下架了,被逼无奈只有做了;拼多多的尿性就是什么东西都得买他的,容器、数据库、redis,连出云访问都要花钱申请,真心无语。
言归正传!
因为拼多多云上其实就是一个redis是服务器,只是做了多开,所以我们普通的项目想要放上去就会报错:
org.springframework.dao.InvalidDataAccessApiUsageException: ERR unknown command `CONFIG`, with args beginning with: `get`, `notify-keyspace-events`,
经过多方查找,终于找到解决方法
在项目中找到redis配置文件,我的是:spring-redis.xml
在里面加上
xmlns:util="http://www.springframework.org/schema/util"
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util.xsd
<!-- Redis 连接池 配置 -->
<bean id="redisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
<!--<property name="maxActive" value="32"></property>-->
<property name="maxIdle" value="6"></property>
<!--<property name="maxWait" value="15000"></property>-->
<property name="minEvictableIdleTimeMillis" value="300000"></property>
<property name="numTestsPerEvictionRun" value="3"></property>
<property name="timeBetweenEvictionRunsMillis" value="60000"></property>
<!--<property name="whenExhaustedAction" value="1"></property>-->
</bean>
<!-- 让Spring Session不再执行config命令 -->
<util:constant static-field="org.springframework.session.data.redis.config.ConfigureRedisAction.NO_OP"/>
完的配置就是:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.2.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<!-- 其他配置 -->
<context:annotation-config/>
<!-- Redis 连接池 配置 -->
<bean id="redisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
<!--<property name="maxActive" value="32"></property>-->
<property name="maxIdle" value="6"></property>
<!--<property name="maxWait" value="15000"></property>-->
<property name="minEvictableIdleTimeMillis" value="300000"></property>
<property name="numTestsPerEvictionRun" value="3"></property>
<property name="timeBetweenEvictionRunsMillis" value="60000"></property>
<!--<property name="whenExhaustedAction" value="1"></property>-->
</bean>
<!-- spring集成redis -->
<!-- Spring-redis连接池管理工厂 -->
<bean id="jedisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory" destroy-method="destroy">
<property name="hostName" value="${redis.hostName}"/>
<property name="port" value="${redis.port}"/>
<property name="database" value="${redis.database}"/>
<property name="password" value="${redis.password}" />
<property name="timeout" value="${redis.timeout}"/>
<property name="usePool" value="${redis.usePool}"/>
</bean>
<!-- 使用spring-session把http session放到redis里 -->
<bean id="redisHttpSessionConfiguration" class="org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration">
<property name="maxInactiveIntervalInSeconds" value="1800"/>
</bean>
<!-- 让Spring Session不再执行config命令 -->
<util:constant static-field="org.springframework.session.data.redis.config.ConfigureRedisAction.NO_OP"/>
</beans>
共同学习才是王道!