用Redis的时候出现的问题

问题一:

***************************
APPLICATION FAILED TO START
***************************

Description:

Parameter 0 of method redisTemplate in org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration required a bean of type 'org.springframework.data.redis.connection.RedisConnectionFactory' that could not be found.

The injection point has the following annotations:
    - @org.springframework.beans.factory.annotation.Autowired(required=true)

The following candidates were found but could not be injected:
    - Bean method 'redisConnectionFactory' in 'JedisConnectionConfiguration' not loaded because @ConditionalOnClass did not find required classes 'org.apache.commons.pool2.impl.GenericObjectPool', 'redis.clients.jedis.Jedis'
    - Bean method 'redisConnectionFactory' in 'LettuceConnectionConfiguration' not loaded because @ConditionalOnClass did not find required class 'io.lettuce.core.RedisClient'

具体见图:


image.png

这个是在使用redis的时候依赖添加错误了

错误的依赖


            org.springframework.data
            spring-data-redis
            2.1.3.RELEASE
        

正确的依赖


            org.springframework.boot
            spring-boot-starter-redis
            1.4.0.RELEASE
        

问题二:

2020-02-06 18:45:36.823 ERROR 10940 --- [nio-8012-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.data.redis.serializer.SerializationException: Cannot serialize; nested exception is org.springframework.core.serializer.support.SerializationFailedException: Failed to serialize object using DefaultSerializer; nested exception is java.lang.IllegalArgumentException: DefaultSerializer requires a Serializable payload but received an object of type [com.redisdemo.demo.entity.User]] with root cause

java.lang.IllegalArgumentException: DefaultSerializer requires a Serializable payload but received an object of type [com.redisdemo.demo.entity.User]
image.png

工具类SerializeUtil序列化时无法识别User对象,修改User类实现Serializable接口(public class User implements Serializable),问题解决。如下图:


image.png

问题三:

2020-02-06 20:54:38.762 ERROR 11828 --- [nio-8012-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.data.redis.RedisConnectionFailureException: Cannot get Jedis connection; nested exception is redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool] with root cause

redis.clients.jedis.exceptions.JedisDataException: ERR Client sent AUTH, but no password is set
image.png

问题看起来很清楚,这句:ERR Client sent AUTH, but no password is set,它的意思就是redis服务器没设置密码,这里还设置了password,而且即使是空“”也不行。把整个password去掉,重启就可以啦

image.png

你可能感兴趣的:(用Redis的时候出现的问题)