Disable a MBean via JConsole


#1

Hello

I need to manage a bean (e.g. disable it from JConsole) in my project.

public static void main(String[] args) {
setSystemProperties(args);
SpringApplication springApplication = new SpringApplication(myMain.class);
springApplication.addListeners(new myWriter());

ApplicationContext context = new AnnotationConfigApplicationContext(myMain.class);
SingletonBeanRegistry beanRegistry = ((ConfigurableApplicationContext)context).getBeanFactory();
TestBean testBean = new TestBean();
beanRegistry.registerSingleton("TestBean", testBean);

springApplication.run(args);

}

I got the following exception from this line of code ApplicationContext context = new AnnotationConfigApplicationContext(myMain.class);

Caused by: org.hibernate.cache.NoCacheRegionFactoryAvailableException: Second-level cache is used in the application, but property hibernate.cache.region.factory_class is not given; please either disable second level cache or set correct region factory using the hibernate.cache.region.factory_class setting and make sure the second level cache provider (hibernate-infinispan, e.g.) is available on the classpath.

Here is my YML file config settings.
jpa:
hibernate.ddl-auto: update
generate-ddl: true
properties:
hibernate:
cache:
use_second_level_cache: false
use_query_cache: false
generate_statistics: false

Please let me know how I could fix this issue. Thanks so much!


#2

The exception does not have anything to do with the question title.

The problem is caused by a missing dependency which is also indicated in the exception message.


#3

Hello ,

Thanks so much for your responses on this. I forgot to include the last 2 lines in my settings yesterday. I actually defined this dependency and I have used this for a long time. Also, I actually have this use_second_level_cache: false setting. The error message said I should set it to false which I did.

jpa:
hibernate.ddl-auto: update
generate-ddl: true
properties:
hibernate:
cache:
use_second_level_cache: false
use_query_cache: false
generate_statistics: false
region:
factory_class: org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory

This particular exception got triggered by this one line of new code I added ApplicationContext context = new AnnotationConfigApplicationContext(myMain.class);. Could you please let me know what I might have missed?

Thanks so much!


#4

You need to remove this property:

factory_class: org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory

if you don’t need the 2nd-level cache.


#5

Hello,
Thanks so much for your great help on this!