備忘 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