Java 在 Spring 应用程序中禁用 JMX
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28607506/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Disabling JMX in a spring application
提问by OntZ
I'm trying to disable jmx so that i don't get org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mbeanExporter'anymore.
我正在尝试禁用 jmx,这样我就不会再收到 org.springframework.beans.factory.BeanCreationException: Error created bean with name 'mbeanExporter'anymore。
I've found a partial answer saying that I should include this in the application.properties file:
我找到了一个部分答案,说我应该在 application.properties 文件中包含它:
spring.datasource.jmx-enabled=false
spring.datasource.jmx-启用=假
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?
所以我用那一行创建了文件。但是我如何确保 Spring 能够准确读取它呢?我需要在 spring.xml 中编辑一些东西吗?如果有,在哪里?
采纳答案by farrellmr
Are you using spring boot? If so you just need to place the file in src\main\resources\application.properties by default
你用的是弹簧靴吗?如果是这样,您只需要默认将文件放在 src\main\resources\application.properties 中
You can check sample projects here https://github.com/spring-projects/spring-boot/tree/master/spring-boot-samples
您可以在此处查看示例项目https://github.com/spring-projects/spring-boot/tree/master/spring-boot-samples
回答by MattC
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
您需要禁用 application.properties 文件中的设置(如果未设置,它会自动打开)。编辑或创建此文件: 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.
那是针对 Maven 项目的,所以如果不是在 Maven 中,只需将“资源”与您的 java 文件夹放在同一级别。
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
如果要添加其他设置,这里是所有选项:http: //docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html
回答by senjin.hajrulahovic
You could try to disable jmx autoconfiguration:
您可以尝试禁用 jmx 自动配置:
@EnableAutoConfiguration(exclude={JmxAutoConfiguration.class})
回答by Johnu
In my case, it was IntelliJ.
就我而言,它是 IntelliJ。
IntelliJ have a setting "Enable JMX agent" in the run configuration. This should be unchecked to disable JMX.
IntelliJ 在运行配置中有一个设置“启用 JMX 代理”。应取消选中此项以禁用 JMX。
If checked, this will override any setting that you make in the application via properties/yml.
如果选中,这将覆盖您通过 properties/yml 在应用程序中所做的任何设置。