SpringBoot2.x版本中,使用SpringSession踩坑记

Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘org.springframework.boot.autoconfigure.session.SessionAutoConfiguration$ServletSessionRepositoryValidator’: Invocation of init method failed; nested exception is org.springframework.boot.autoconfigure.session.SessionRepositoryUnavailableException: No session repository could be auto-configured, check your configuration (session store type is ‘redis’)
这是因为缺少了spring-session-data-redis依赖。
关于SpringBoot2.X中,引用SpringSession,同时使用Redis存储缓存数据需要进行如下配置:

	
	<dependency>
		<groupId>org.springframework.sessiongroupId>
		<artifactId>spring-session-coreartifactId>
	dependency>
	
	<dependency>
		<groupId>org.springframework.sessiongroupId>
		<artifactId>spring-session-data-redisartifactId>
	dependency>
	#使用使用Redis缓存session数据
	spring.session.store-type=REDIS
	#Redis服务器地址
	spring.redis.host=127.0.0.1
	#Redis服务器端口号
	spring.redis.port=6379

总结:在SpringBoot2.x的版本中,引用spring-session-core时,不是对spring-session-data-redis进行加载,需要用户自己添加关于spring-session与redis的关联依赖。

你可能感兴趣的:(SpringBoot)