How can I retrieve the CacheManager registered during Spring Boot initialization?

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

I doubt anyone here will be able to answer your question. You should rather ask this question in Spring forums. Either way, if Spring registers the CacheManager into Hibernate ORM, you should be able to auto-wire that bean and then you can work with it, no?

Hi beikov, thanks for your reply. Yeah, Spring Forums are closed. They thought it would be a good thing to go with Stack Overflow instead. But on SO you won’t get quality answers away from happy path questions.

I have tried to inject the CacheManager, but the injected one is the Spring Boot’s default manager which has no access to the Hibernate caches. I’m not that expert, but I think that has to do something with the JCache facade inbetween.

Since I don’t know exactly what is going under the hood (as I said, I’m not an expert) I would appreciate to somewhere find a proper solution of how to use and manage Spring Boot 3/Hibernate 6/Ehcache 3. But this just seems to be a silly wish.

However, thanks and have a nice day.