首先說明環境不是我搭建的,然后因項目需要添加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–>-->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
<version>2.4.2</version>
</dependency>
如果你的代碼中注入RedisTemplate等元素報錯(紅線),直接檢查jar包