I have Two CacheManagers defined in different places (by different teams):
eg:
@Configuration
@EnableCaching
public ConfigClassOne {
@Bean
public CacheManager myCacheManager() {
return new ConcurrentMapCacheManager("someCacheName");
}
}
and elsewhere in the code (that my app consumes but is not responsible for):
@Configuration
@EnableCaching
public class CacheConfiguration {
@Bean
public CacheManager otherCacheManager () {
return new ConcurrentMapCacheManager(CacheConstants.SOME_CACHE_NAME,
CacheConstants.SOME_OTHER_NAME);
}
}
I get unsatisfied bean exception when trying to do getBean because there are two CacheManager.class results.
The problem is, because this is external to me, I do not want to rely on them making the cache, nor set mine to primary as they may receive it.
I've tried setting bean name, bean qualifier but all result in either no results or 2 results (both exceptions).
I tried creating a CompositeManager (primary) that takes theirs on with ours but this is not an ideal solution..
Even stranger, when running integration test I see the following:
In debug I can see that both autowired beans (classes that use them) on each side (mine and theirs) get their respective managers correctly even without primary, but the test fails because at some point it runs some refresh when autowiring to another class the class that holds the bean instance and THEN it tries to do getbean and fails (perhaps something with mockito?)
Is there a way to resolve this issue?