In a Spring Boot 3 application I use Ehcache 3 as 2nd level cache. Spring Boot registers Statistic Beans with CacheManager=classpath.ehcache.xml:
o.e.s.o.t.o.p.UpfrontAllocatingPageSource : Allocating 1MB in chunks
o.e.c.EhcacheManager : Cache 'email-status-cache' created in EhcacheManager.
o.e.j.Eh107CacheManager : Registering Ehcache MBean javax.cache:type=CacheStatistics,CacheManager=classpath.ehcache.xml,Cache=email-status-cache
I now want to get access not only to the MXBeans but also to specific cache regions. What I have is the following base situation, from where I want to go on and retrieve the dedicated caches corresponding to the statistic beans:
String cacheManagerName = "classpath.ehcache.xml";
String objectNamePattern = String.format("javax.cache:type=CacheStatistics,CacheManager=%s,Cache=*", cacheManagerName);
MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
try {
Set<ObjectInstance> cacheBeans = mBeanServer.queryMBeans(ObjectName.getInstance(objectNamePattern), null);
} catch (MalformedObjectNameException e) { }
I tried to obtain a CacheManager like this:
URI ehcacheXmlUri = new ClassPathResource("ehcache.xml").getURI();
CachingProvider cachingProvider = Caching.getCachingProvider();
CacheManager cacheManager = cachingProvider.getCacheManager(ehcacheXmlUri, getClass().getClassLoader());
But this registers a new Manager and a new set of MXBeans. That is not what I want. I just want to get access to the yet registered beans without creating new ones and at the same time access to the underlying caches.
Does anybody know how to achieve this?
Many thanks for any help