Could not autowire. No beans of 'RedisConnectionFactory' type found

weixin_38705522 2019-05-16 07:19:03
RedisConnectionFactory factory 提示错误


@Configuration
public class RedisConfig {

@Bean
public RedisTemplate<String,Object> redisTemplate(RedisConnectionFactory factory){
RedisTemplate<String,Object> template = new RedisTemplate<>();
template.setConnectionFactory(factory);

Jackson2JsonRedisSerializer serializer = new Jackson2JsonRedisSerializer(Object.class);
ObjectMapper mapper = new ObjectMapper();
mapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
mapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
serializer.setObjectMapper(mapper);
template.setValueSerializer(serializer);
//使用Jackson2JsonRedisSerializer来序列化和反序列化redis的value值
template.setHashValueSerializer(serializer);
//使用Jackson2JsonRedisSerializer来序列化和反序列化redis的value值
template.setStringSerializer(new StringRedisSerializer());
template.setHashKeySerializer(new StringRedisSerializer());

template.afterPropertiesSet();
return template;
}

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.che</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>springbootDemo</name>
<description>Demo project for Spring Boot</description>

<properties>
<java.version>1.8</java.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.9.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.8</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>

...全文
14558 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
听丶语音未散 2022-03-29
  • 打赏
  • 举报
回复

这个我也遇到过,第一次解决的方案是重新手动创建项目,第二次又遇到了。怎么解决?

weixin_38705522 2019-05-16
  • 打赏
  • 举报
回复
引用 1 楼 对梦想的牵挂 的回复:
Redis服务没连上吧

不是吧 还没编译呢
对梦想的牵挂 2019-05-16
  • 打赏
  • 举报
回复
Redis服务没连上吧
weixin_38705522 2019-05-16
  • 打赏
  • 举报
回复
引用 6 楼 对梦想的牵挂 的回复:
[quote=引用 5 楼 weixin_38705522 的回复:] [quote=引用 4 楼 对梦想的牵挂 的回复:] [quote=引用 2 楼 weixin_38705522 的回复:] [quote=引用 1 楼 对梦想的牵挂 的回复:] Redis服务没连上吧
不是吧 还没编译呢[/quote] 没编译?你是说还没运行就报错了是么? 这样的话你看把Redis的依赖的版本号加上,看看是不是和jedis版本不一致造成的[/quote] 发现创建springboot项目的时候勾上web就没问题了,之前没有勾任何东西。[/quote] 那就是之前缺少spring实现web功能的相关依赖。[/quote] 是的
对梦想的牵挂 2019-05-16
  • 打赏
  • 举报
回复
引用 5 楼 weixin_38705522 的回复:
[quote=引用 4 楼 对梦想的牵挂 的回复:] [quote=引用 2 楼 weixin_38705522 的回复:] [quote=引用 1 楼 对梦想的牵挂 的回复:] Redis服务没连上吧
不是吧 还没编译呢[/quote] 没编译?你是说还没运行就报错了是么? 这样的话你看把Redis的依赖的版本号加上,看看是不是和jedis版本不一致造成的[/quote] 发现创建springboot项目的时候勾上web就没问题了,之前没有勾任何东西。[/quote] 那就是之前缺少spring实现web功能的相关依赖。
weixin_38705522 2019-05-16
  • 打赏
  • 举报
回复
引用 4 楼 对梦想的牵挂 的回复:
[quote=引用 2 楼 weixin_38705522 的回复:] [quote=引用 1 楼 对梦想的牵挂 的回复:] Redis服务没连上吧
不是吧 还没编译呢[/quote] 没编译?你是说还没运行就报错了是么? 这样的话你看把Redis的依赖的版本号加上,看看是不是和jedis版本不一致造成的[/quote] 发现创建springboot项目的时候勾上web就没问题了,之前没有勾任何东西。
对梦想的牵挂 2019-05-16
  • 打赏
  • 举报
回复
引用 2 楼 weixin_38705522 的回复:
[quote=引用 1 楼 对梦想的牵挂 的回复:] Redis服务没连上吧
不是吧 还没编译呢[/quote] 没编译?你是说还没运行就报错了是么? 这样的话你看把Redis的依赖的版本号加上,看看是不是和jedis版本不一致造成的
浪费七年时间 2019-05-16
  • 打赏
  • 举报
回复
完整的异常堆栈信息有没有

67,550

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧