SpringBoot 整合Redis客户端lettuce,LPOS异常分析

项目场景:

项目场景:SpringBoot 整合Redis客户端lettuce。


问题描述

整合Redis客户端lettuce出现异常:

Caused by: java.lang.NoSuchFieldError: LPOS
	at org.springframework.data.redis.connection.lettuce.LettuceConnection$TypeHints.<init>(LettuceConnection.java:1173)
	at org.springframework.data.redis.connection.lettuce.LettuceConnection.<clinit>(LettuceConnection.java:96)
	at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory.afterPropertiesSet(LettuceConnectionFactory.java:340)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1863)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1800)
	... 111 common frames omitted

原因分析:

最终分析定位为版本问题,spring-boot-starter-data-redis 2.2.5.RELEASE 关联子包spring-data-redis: 2.5.6.RELEASE,lettuce-core:5.2.2.RELEASE,其中spring-data-redis: 2.5.6.RELEASE版本过高,需要
降低至2.2.5.RELEASE版本。


解决方案:

修改POM.xml文件

		<parent>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-parent</artifactId>
			<version>2.2.5.RELEASE</version>
			<relativePath />
		</parent>
    .......
        <!-- 1.SpringWeb模块,引入Web服务器undertow -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-undertow</artifactId>
        </dependency>
        
       <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-redis</artifactId>
            <exclusions>
                <!-- 排除spring-data-redis高版本2.5.6.RELEASE -->
                <exclusion>
                    <groupId>org.springframework.data</groupId>
                    <artifactId>spring-data-redis</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <!-- 指定2.2.5.RELEASE版本 -->
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-redis</artifactId>
            <version>2.2.5.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-pool2</artifactId>
            <version>2.9.0</version>
        </dependency>

mvn包间关系如图:
依赖关系
application.yml文件配置redis:

spring:
  redis:
    # 地址
    host: 127.0.0.1
    # 端口,默认为6379
    port: 6379
    # 数据库索引
    database: 0
    # 密码
    password: 123456
    # 连接超时时间
    timeout: 200
    lettuce:
      pool:
        max-active: 8
        max-wait: -1ms
        max-idle: 8
        min-idle: 0
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值