使用Lettuce作为客户端的Spring Redis Connection(通过XML设置)

时间:2017-03-15 11:55:20

标签: java spring spring-mvc redis lettuce

我正在尝试通过我的spring mvc应用程序连接redis进行会话存储。我使用Lettuce作为redis客户端。在这样做时,我遇到一个错误说明..

NoClassDefFoundError:com / lamdaworks / redis / protocol / CommandEncoder 在org.springframework.session.data.redis.RedisOperationSessionRepository $ RedisSession.saveDelta(RedisOperationSessionRepository.java:788)

当我使用 jedis client api时,同样正常。

注意:我没有使用像maven这样的构建工具。我已经下载了独立的罐子。以下是列表和版本

lettuce-3.5.0.Final.jar (也是https://mvnrepository.com/artifact/biz.paluch.redis/lettuce/3.5.0.Final中提及的所有支持罐子)

弹簧数据redis的-1.7.1.release.jar

我的app-config.xml如下

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
    http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context.xsd">

 <context:annotation-config/>
    <bean class="org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration"/>
   <bean class="org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory" p:hostName="127.0.0.1" p:port="6379" p:password="password"/>   
   </beans> 

web.xml如下

<?xml version="1.0" encoding="UTF-8"?>
 <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
        http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">

    <display-name>Spring Session with Servlet</display-name> 
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/spring/app-config.xml</param-value>
</context-param>
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<filter>
     <filter-name>springSessionRepositoryFilter</filter-name>
     <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
    <filter-name>springSessionRepositoryFilter</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>ERROR</dispatcher>
</filter-mapping>
</web-app>   

请协助解决任何可能的错误配置或错误。

谢谢!

0 个答案:

没有答案