Spring boot: I can make a cache, but turning it into a bean fails

Viewed 17

This generates an error saying I create a circular dependency.

@Configuration
@EnableCaching
public class MyConfig {

    @Bean
    public Cache cache(CacheManager cacheManager) {
        return cacheManager.getCache("acl_cache");
    }
}

But when I do this, it works:

@Configuration
@EnableCaching
public class MyConfig {

    @Bean
    public MyClass myClass(CacheManager cacheManager) {
        Cache cache = cacheManager.getCache("acl_cache");
        return new MyClass(cache);
    }
}

In both cases I made a new cache, but in the first case it's a bean.

Why do spring boot thinks this is a circular dependency in one case, and not in the other?

PS: MyClass is not important here. In reality I use SpringCacheBasedAclCache who needs more parameters

0 Answers
Related