备忘 springboot 整合ehcache,注入CacheManager时提示 required a bean of type 'org.springframework.cache.CacheManager' that could not be found


问题因人而异,此处仅做备忘

整合过程:

1、添加maven依赖

        <dependency>
            <groupId>net.sf.ehcache</groupId>
            <artifactId>ehcache</artifactId>
            <version>2.10.6</version>
        </dependency>

2、开启springboot缓存

@EnableCaching
@SpringBootApplication
public class EhcachetestApplication {

    public static void main(String[] args) {
        SpringApplication.run(EhcachetestApplication.class, args);
    }

}

3、在使用位置注入 org.springframework.cache.CacheManager

 

注:上面飘红并不是报错的原因,可忽略。

 4、打包测试,报 required a bean of type 'org.springframework.cache.CacheManager' that could not be found

5、增加 spring-boot-starter-cache 依赖

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

6、再次打包测试,一切OK

 

问题原因分析:

spring-boot-starter-cache 是springboot缓存功能的依赖,如果要开启springboot cache必需添加该依赖。这次因为这个地方忽视,造成调错花费了不少时间,记录下来加深记忆!


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM