Skip to content
This repository was archived by the owner on Feb 23, 2023. It is now read-only.

Commit 2d007cb

Browse files
committed
Update Tomcat substitutions to allow controlling JMX support
Closes gh-935
1 parent 8bbf9a7 commit 2d007cb

File tree

4 files changed

+35
-2
lines changed

4 files changed

+35
-2
lines changed

spring-aot/src/main/java/org/springframework/aot/factories/CodeGenerator.java

+3
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ public CodeGenerator(AotOptions aotOptions) {
6666
if (aotOptions.isRemoveSpelSupport()) {
6767
staticBlock.addStatement("System.setProperty(\"spring.spel.ignore\", \"true\")");
6868
}
69+
if (!aotOptions.isRemoveJmxSupport()) {
70+
staticBlock.addStatement("System.setProperty(\"spring.jmx.ignore\", \"false\")");
71+
}
6972

7073
// Make sure we take the native codepath even on the JVM, can be useful with the tracing agent
7174
// TODO Allow to disable it via a flag
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright 2019-2021 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.nativex.substitutions;
18+
19+
import java.util.function.BooleanSupplier;
20+
21+
public class RemoveJmxSupport implements BooleanSupplier {
22+
23+
@Override
24+
public boolean getAsBoolean() {
25+
return Boolean.valueOf(System.getProperty("spring.jmx.ignore", "true"));
26+
}
27+
28+
}

spring-native/src/main/java/org/springframework/nativex/substitutions/micrometer/Target_TomcatMetrics.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import org.springframework.nativex.substitutions.CatalinaManagerIsAround;
2020
import org.springframework.nativex.substitutions.OnlyIfPresent;
21+
import org.springframework.nativex.substitutions.RemoveJmxSupport;
2122

2223
import com.oracle.svm.core.annotate.Substitute;
2324
import com.oracle.svm.core.annotate.TargetClass;
@@ -30,7 +31,7 @@
3031
* @author Andy Clement
3132
*/
3233
@TargetClass(className = "io.micrometer.core.instrument.binder.tomcat.TomcatMetrics",
33-
onlyWith = {OnlyIfPresent.class, CatalinaManagerIsAround.class})
34+
onlyWith = {OnlyIfPresent.class, CatalinaManagerIsAround.class, RemoveJmxSupport.class})
3435
final class Target_TomcatMetrics {
3536

3637
@Substitute

spring-native/src/main/java/org/springframework/nativex/substitutions/tomcat/Target_Registry.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@
2222
import org.apache.tomcat.util.modeler.Registry;
2323

2424
import org.springframework.nativex.substitutions.OnlyIfPresent;
25+
import org.springframework.nativex.substitutions.RemoveJmxSupport;
2526

2627
// To avoid Registry instantiation and JmxMBeanServer usage
27-
@TargetClass(className = "org.apache.tomcat.util.modeler.Registry", onlyWith = { OnlyIfPresent.class })
28+
@TargetClass(className = "org.apache.tomcat.util.modeler.Registry", onlyWith = { OnlyIfPresent.class, RemoveJmxSupport.class })
2829
final class Target_Registry {
2930

3031
@Alias

0 commit comments

Comments
 (0)