踩坑日记:Error creating bean with name 'enableRedisKeyspaceNotificationsInitializer' defined in class

第一次接触redis与spring session,二话不说,开始在CSDN上找各种教程,然后各种Ctrl+c。
首先pom.xml,新增两个依赖,好多博文里只列出一个

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.session</groupId>
    <artifactId>spring-session-data-redis</artifactId>
</dependency>

接着,配置文件application.properties。

spring.redis.host=127.0.0.1
spring.redis.port=6379
spring.redis.password=123
spring.redis.database=0

坑:这里的password 如果redis没有设置密码填空,因为安装redis默认的密码为空,然后就改成下面这种就ok了 。

spring.redis.host=127.0.0.1
spring.redis.port=6379
spring.redis.password=
spring.redis.database=0

最后,spring boot 启动类Application 添加注解@EnableRedisHttpSession

@SpringBootApplication
@EnableRedisHttpSession
public class Application extends WebMvcConfigurationSupport {

    public static void main(String[] args){

        SpringApplication.run(Application.class,args);

    }
}

end!

发布了24 篇原创文章 · 获赞 11 · 访问量 5424

猜你喜欢

转载自blog.csdn.net/weixin_44037376/article/details/96839369