@Component工具类中自动注入了一个bean,在测试了类中自动注入了工具类以及bean,自动注入的工具类获取不到bean

通过@Bean 将Redistemplate 对象交给spring容器;
再通过@Component 将一个工具类交给spring容器,工具类中自动注入了 Redistemplate 类;
但得是在测试类中通过自动注入获取两个类,工具类中的RedisTemplate为空,但是直接自动注入RedisTemplate却可以获取。
是不是加载时机的问题。

工具类:

img


Redis配置类并将redisTemplate交给spring容器管理

img


测试

img


结果:

img


打印输出:

img

RedisUtils里@Autowired改成@Resource试试

我看下你的配置文件 或者单独私我 这个好搞