我们有一个带有执行器的Spring Boot应用程序。我们正在尝试禁用远程JMX访问,但是以某种方式无法正常工作。我们尝试了以下设置:
在Tomcat启动选项中:
-Dcom.sun.management.jmxremote=false
-Dcom.sun.management.jmxremote.password.file=....../jmxremote.password
-Dcom.sun.management.jmxremote.registry.ssl=true
-Djava.security.manager
-Djava.security.policy=jmx.policy
-Djavax.net.ssl.keyStore=....jks
-Djavax.net.ssl.keyStorePassword=****
-Djavax.net.ssl.trustStore=.....jks
-Djavax.net.ssl.trustStorePassword=****
在application.properties中:
spring.jmx.enabled=false
spring.datasource.jmx-enabled=false
endpoints.jmx.enabled=false
spring.jmx.server=localhost
但是,我们仍然能够从远程系统访问JMX。选项spring.jmx.enabled
的唯一区别是特定于Spring的MBean不可用,而其他MBean仍然可用。
如何禁用对JMX的远程访问?理想情况下,从本地计算机连接时,我们仍然希望访问,但是如果需要,也可以将其禁用。
已添加 build.gradle
buildscript {
ext {
springBootVersion = '1.5.16.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply from: "../dependencies.gradle"
repositories {
mavenCentral()
}
bootRepackage {
enabled = false
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
providedRuntime project(':....')
compile project(':...')
compile project(':...')
compile project(':...')
compile project(':...')
compile group: 'com.hazelcast', name: 'hazelcast', version: '3.12'
compile group: 'com.hazelcast', name: 'hazelcast-client', version: '3.12'
compile group: 'org.hibernate', name: 'hibernate-core', version: '5.2.11.Final'
compile group: 'org.aspectj', name: 'aspectjweaver', version: '1.9.2'
compile group: 'org.apache.poi', name: 'poi', version: '4.0.1'
compile group: 'org.apache.poi', name: 'poi-ooxml', version: '4.0.1'
compileOnly group: 'org.projectlombok', name: 'lombok', version: '1.18.2'
providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
compile("org.springframework.boot:spring-boot-starter-web")
compile("org.springframework.boot:spring-boot-starter-actuator")
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile group: 'org.mockito', name: 'mockito-all', version: '1.9.5'
}
答案 0 :(得分:0)
发生了完全相同的问题,并使用以下设置解决了该问题:
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.local.only=true
-Dcom.sun.management.jmxremote.authenticate=true
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.port=1099
-Dcom.sun.management.jmxremote.host=localhost
-Djava.rmi.server.hostname=localhost
-Dcom.sun.management.jmxremote.password.file=<path to jmxremote.password>
-Dcom.sun.management.jmxremote.access.file=<path to jmxremote.access>
请注意,即使显然不需要,也必须对属性进行排序并将其显式设置为其默认值 。
答案 1 :(得分:0)
基于Diederik的解决方案,需要更改两个属性
将身份验证设置为true。并指定password.file和access.file。
将主机设置为localhost或127.0.0.1。
如果authenticate为false或主机不是localhost,则将启用远程访问。
这里是一个样本
-Dcom.sun.management.jmxremote \
-Dcom.sun.management.jmxremote.port=1099 \
-Dcom.sun.management.jmxremote.host=localhost \
-Dcom.sun.management.jmxremote.authenticate=true \
-Dcom.sun.management.jmxremote.password.file=<path to password file> \
-Dcom.sun.management.jmxremote.access.file=<path to access file> \
-Dcom.sun.management.jmxremote.ssl=false \