19

I'm trying to disable jmx so that i don't get:

org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'mbeanExporter'anymore. 

I've found a partial answer saying that I should include this in the application.properties file:

  • spring.datasource.jmx-enabled=false

So I created the file with that one line. But how do I make sure that Spring acutally reads it? Do I need to edit something in spring.xml? If so, where?

Manuel Jordan
  • 15,253
  • 21
  • 95
  • 158
OntZ
  • 263
  • 1
  • 3
  • 12

4 Answers4

41

You need to disable the setting in your application.properties file (it is automatically turned on if not set). Either edit or create this file: src/main/resources/config/application.properties

That is for a maven project, so if not in maven, just put 'resources' at the same level as your java folder.

You will just need this single line in the file (it can be blank otherwise):

spring.jmx.enabled=false

If you want to add other settings, here are all the options: http://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html

MattC
  • 5,874
  • 1
  • 47
  • 40
  • 1
    Just in Case you come here like me wondering why you could not disable it during tests with ``spring.jmx.enabled=false``.Make sure you do not have the ``@EnableMBeanExport`` additionally on your application configuration. It seems to override/rule the Property. – Benjamin Peter Apr 18 '18 at 11:42
  • Hello, can we set spring?JMX.enabled=true programmatically like we can set server port through the class same way can we set this property true? – Tirth Timaniya Apr 01 '21 at 06:43
24

In my case, it was IntelliJ.

IntelliJ have a setting "Enable JMX agent" in the run configuration. This should be unchecked to disable JMX.

If checked, this will override any setting that you make in the application via properties/yml.

Johnu
  • 361
  • 3
  • 5
  • The same applies to Eclipse, I had the same problem and there was a checkbox in the Run configuration which was enabling JMX. – JohnEye Oct 18 '21 at 15:46
2

Are you using spring boot? If so you just need to place the file in src\main\resources\application.properties by default

You can check sample projects here https://github.com/spring-projects/spring-boot/tree/master/spring-boot-samples

farrellmr
  • 1,815
  • 2
  • 15
  • 26
  • Yes, I'm using spring boot and I put the file under src\main\resources. Is that supposed to just fix it and disable JMX? Because in my case this doesn't happen. – OntZ Feb 19 '15 at 13:34
  • That should be enough - your log should show that jmx isnt enabled. Another option to confirm it would be to disable the banner from application.properties as a test - spring.main.show_banner=false – farrellmr Feb 19 '15 at 13:38
  • If not, where am I supposed to use this property in my code to desable JMX for the entire application? – OntZ Feb 19 '15 at 13:39
  • Sorry - I think the property you need to set it spring.jmx.enabled=false – farrellmr Feb 19 '15 at 13:43
  • Are you doing a clean build and install? – farrellmr Feb 19 '15 at 13:43
  • Clean build and instal, along with spring.jmx.enabled=false solved it, thank you! Well, at least it solved the JMX problem. Now I'm getting some hibernate JPA autoconfiguration problems, but to be fair that's besides the scope of this question. – OntZ Feb 19 '15 at 13:54
  • No problem - check the samples project for examples – farrellmr Feb 19 '15 at 13:59
  • NB The samples have been renamed "smoke tests" (https://github.com/spring-projects/spring-boot/commit/d5c0009c6eb0e77e4e1013d149d33de7dccdbd4d) and are now here: https://github.com/spring-projects/spring-boot/tree/master/spring-boot-tests/spring-boot-smoke-tests – Richard Fearn Nov 12 '19 at 10:49
1

You could try to disable jmx autoconfiguration:

@EnableAutoConfiguration(exclude={JmxAutoConfiguration.class})
senjin.hajrulahovic
  • 2,961
  • 2
  • 17
  • 32