zoukankan      html  css  js  c++  java
  • spring boot集成redis的血泪史


    首先说明环境不是我搭建的,然后因项目需要添加redis的时候,麻烦来了。
    springboot 用的是1.5.9
    因为以前弄过redis,所以直接拿过来,麻烦了首先是莫名的错误,连项目都启动不了。但是最后一句是显示redis拿不到连接

    问题一、redis拿不到连接

    首先 telnet redis看能否连接上
    如果能,找到redis的安装文件有一个redis.windows.conf和redis.windows-service.conf文件,找到bind 127.0.0.1,改成bind 0.0.0.0
    这样能保证远程telnet上。
    其实这样问题并没有解决。
    接着又是报错找不到StringRedisTemplate等等一些实例化的bean
    网上看了一些:注解@Autowired换成@Resource的,这个其实没什么太大作用
    最后发现是jar包版本的问题。

    问题二、jar包版本的问题

    因为我的redis安装的是2.8.9版本
    于是jedis用了2.9的版本,直接OK了
    下面是pom.xml文件
           <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-data-redis</artifactId>
                <version>2.0.4.RELEASE</version>
            </dependency>
            <!-- https://mvnrepository.com/artifact/redis.clients/jedis -->
            <dependency>
                <groupId>redis.clients</groupId>
                <artifactId>jedis</artifactId>
                <version>2.9.0</version>
            </dependency>
            <!--spring2.0集成redis所需common-pool2&ndash;&gt;-->
            <dependency>
                <groupId>org.apache.commons</groupId>
                <artifactId>commons-pool2</artifactId>
                <version>2.4.2</version>
            </dependency>    

    如果你的代码中注入RedisTemplate等元素报错(红线),直接检查jar包
    
    






  • 相关阅读:
    tcpip协议
    Linux特殊文件使用原理
    shell之常用内置变量
    SSM框架CRUD小案例
    个人博客开发笔记
    蓝天筹项目开发记录
    二叉平衡树AVL的插入与删除(java实现)
    二叉搜索树(java实现)
    树的基本操作
    SQL连接
  • 原文地址:https://www.cnblogs.com/zeussbook/p/9910533.html
Copyright © 2011-2022 走看看