后端项目报错:No bean named ‘redisTemplate‘ available

启动后端项目,报如下错误:com.xxx.xxx.cache.exception.CacheException:[No bean name 'redisTemplate' available];caused by org.springframework.beans.factory.NoSuchBean

DefinitionException:No bean named 'redisTemplate' available。

原因在于pom.xml文件中未引入与redis相关的依赖包但在配置项的缓存设置中却涉及了redis,加入如下依赖即可:

<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-data-redis</artifactId>

</dependency>

<dependency>

<groupId>org.springframework.data</groupId>

<artifactId>spring-data-redis</artifactId>

</dependency>

<dependency>

<groupId>org.springframework.session</groupId>

<artifactId>spring-session-data-redis</artifactId>

</dependency>

如果是单体项目不需要使用到redis,则不引入redis依赖,在application.properties文件或bootstrap.yml文件的缓存设置项中将redis缓存更换为其他缓存方式:

#---xxx-cache.properties----

xxx=redis   =>   xxx=ehcache-local

pte=redis   =>   pte=ehcache-local

wfcache=redis   =>   wfcache=ehcache-local

workbench=redis   =>   workbench=ehcache-local

restful=redis   =>   restful=ehcache-local

猜你喜欢

转载自blog.csdn.net/liu__yuan/article/details/126741047