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.bootgroupId>
			<artifactId>spring-boot-starter-parentartifactId>
			<version>2.2.5.RELEASEversion>
			<relativePath />
		parent>
    .......
        
        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-webartifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.bootgroupId>
                    <artifactId>spring-boot-starter-tomcatartifactId>
                exclusion>
            exclusions>
        dependency>
        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-undertowartifactId>
        dependency>
        
       <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-data-redisartifactId>
            <exclusions>
                
                <exclusion>
                    <groupId>org.springframework.datagroupId>
                    <artifactId>spring-data-redisartifactId>
                exclusion>
            exclusions>
        dependency>
        
        <dependency>
            <groupId>org.springframework.datagroupId>
            <artifactId>spring-data-redisartifactId>
            <version>2.2.5.RELEASEversion>
        dependency>
        <dependency>
            <groupId>org.apache.commonsgroupId>
            <artifactId>commons-pool2artifactId>
            <version>2.9.0version>
        dependency>

mvn包间关系如图:
SpringBoot 整合Redis客户端lettuce,LPOS异常分析_第1张图片
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

你可能感兴趣的:(Spring,框架研究,redis,spring,boot,java)