Reputation: 3224
I have implemented application in Spring + Hibernate. To optimize ORM operations I have followed by this tutorial to enable monitoring for Ehcache:
@EnableWebMvc
@EnableSpringDataWebSupport
@EnableCaching
...
public class SpringWebConfig extends WebMvcConfigurerAdapter {
....
@Bean
public EhCacheCacheManager ehCacheManager() {
EhCacheCacheManager cacheManager = new EhCacheCacheManager();
cacheManager.setCacheManager((net.sf.ehcache.CacheManager) ehCacheManagerFactory().getObject());
return cacheManager;
}
@Bean
public EhCacheManagerFactoryBean ehCacheManagerFactory() {
EhCacheManagerFactoryBean cmfb = new EhCacheManagerFactoryBean();
cmfb.setConfigLocation(new ClassPathResource("ehcache.xml"));
cmfb.setShared(true);
return cmfb;
}
@Bean
public ManagementService managementService() {
return new ManagementService(ehCacheManager().getCacheManager(), mBeanServer(), true, true, true, true);
}
@Bean
public MBeanServer mBeanServer() {
MBeanServer bean = ManagementFactory.getPlatformMBeanServer();
return bean;
}
}
However I cannot see any ehache beans in jConsole:
Do you know if I missed something to enable statistics?
Upvotes: 0
Views: 1443
Reputation: 14500
The issue comes from the fact that you are simply creating the ManagementService
but not initialising it.
Your managementService
method needs to invoke the init()
method on the created ManagementService
.
Unless you effectively need access to the ManagementService
for other purposes, exposing it as a bean is not required and you may replace this by a usage of the static ManagementService.registerMBeans(CacheManager, MBeanServer, boolean, boolean, boolean, boolean)
either inside the ehCacheManagerFactory()
or ehCacheManager()
methods.
The static method creates the ManagementService
and initialises it.
Upvotes: 1