Disabling JMX in a spring application
Asked Answered
B

4

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?

Bloemfontein answered 19/2, 2015 at 13:21 Comment(0)
E
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

Erebus answered 19/2, 2015 at 13:32 Comment(8)
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.Bloemfontein
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=falseErebus
If not, where am I supposed to use this property in my code to desable JMX for the entire application?Bloemfontein
Sorry - I think the property you need to set it spring.jmx.enabled=falseErebus
Are you doing a clean build and install?Erebus
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.Bloemfontein
No problem - check the samples project for examplesErebus
NB The samples have been renamed "smoke tests" (github.com/spring-projects/spring-boot/commit/…) and are now here: github.com/spring-projects/spring-boot/tree/master/…Cyril
A
42

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

Averyaveryl answered 15/6, 2015 at 19:59 Comment(2)
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.Abbasid
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?Olimpia
P
26

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.

Pohl answered 9/8, 2019 at 16:32 Comment(1)
The same applies to Eclipse, I had the same problem and there was a checkbox in the Run configuration which was enabling JMX.Chlamydospore
E
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

Erebus answered 19/2, 2015 at 13:32 Comment(8)
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.Bloemfontein
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=falseErebus
If not, where am I supposed to use this property in my code to desable JMX for the entire application?Bloemfontein
Sorry - I think the property you need to set it spring.jmx.enabled=falseErebus
Are you doing a clean build and install?Erebus
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.Bloemfontein
No problem - check the samples project for examplesErebus
NB The samples have been renamed "smoke tests" (github.com/spring-projects/spring-boot/commit/…) and are now here: github.com/spring-projects/spring-boot/tree/master/…Cyril
F
1

You could try to disable jmx autoconfiguration:

@EnableAutoConfiguration(exclude={JmxAutoConfiguration.class})
Forficate answered 1/7, 2019 at 13:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.