|
16 | 16 |
|
17 | 17 | package org.springframework.boot.actuate.autoconfigure.metrics;
|
18 | 18 |
|
19 |
| -import java.io.Closeable; |
20 |
| - |
21 | 19 | import io.micrometer.core.instrument.MeterRegistry;
|
| 20 | +import io.micrometer.core.instrument.binder.MeterBinder; |
22 | 21 | import io.micrometer.core.instrument.binder.jvm.ClassLoaderMetrics;
|
23 | 22 | import io.micrometer.core.instrument.binder.jvm.JvmCompilationMetrics;
|
24 | 23 | import io.micrometer.core.instrument.binder.jvm.JvmGcMetrics;
|
|
31 | 30 | import org.springframework.aot.hint.RuntimeHints;
|
32 | 31 | import org.springframework.aot.hint.RuntimeHintsRegistrar;
|
33 | 32 | import org.springframework.beans.BeanUtils;
|
34 |
| -import org.springframework.beans.factory.BeanClassLoaderAware; |
35 |
| -import org.springframework.beans.factory.DisposableBean; |
36 |
| -import org.springframework.beans.factory.FactoryBean; |
37 | 33 | import org.springframework.boot.autoconfigure.AutoConfiguration;
|
38 | 34 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
39 | 35 | import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
@@ -103,47 +99,9 @@ public JvmCompilationMetrics jvmCompilationMetrics() {
|
103 | 99 | @ConditionalOnClass(name = VIRTUAL_THREAD_METRICS_CLASS)
|
104 | 100 | @ConditionalOnMissingBean(type = VIRTUAL_THREAD_METRICS_CLASS)
|
105 | 101 | @ImportRuntimeHints(VirtualThreadMetricsRuntimeHintsRegistrar.class)
|
106 |
| - VirtualThreadMetricsFactoryBean virtualThreadMetrics() { |
107 |
| - return new VirtualThreadMetricsFactoryBean(); |
108 |
| - } |
109 |
| - |
110 |
| - static final class VirtualThreadMetricsFactoryBean |
111 |
| - implements FactoryBean<Object>, BeanClassLoaderAware, DisposableBean { |
112 |
| - |
113 |
| - private ClassLoader classLoader; |
114 |
| - |
115 |
| - private Class<?> instanceType; |
116 |
| - |
117 |
| - private Object instance; |
118 |
| - |
119 |
| - @Override |
120 |
| - public void setBeanClassLoader(ClassLoader classLoader) { |
121 |
| - this.classLoader = classLoader; |
122 |
| - } |
123 |
| - |
124 |
| - @Override |
125 |
| - public Object getObject() { |
126 |
| - if (this.instance == null) { |
127 |
| - this.instance = BeanUtils.instantiateClass(getObjectType()); |
128 |
| - } |
129 |
| - return this.instance; |
130 |
| - } |
131 |
| - |
132 |
| - @Override |
133 |
| - public Class<?> getObjectType() { |
134 |
| - if (this.instanceType == null) { |
135 |
| - this.instanceType = ClassUtils.resolveClassName(VIRTUAL_THREAD_METRICS_CLASS, this.classLoader); |
136 |
| - } |
137 |
| - return this.instanceType; |
138 |
| - } |
139 |
| - |
140 |
| - @Override |
141 |
| - public void destroy() throws Exception { |
142 |
| - if (this.instance instanceof Closeable closeable) { |
143 |
| - closeable.close(); |
144 |
| - } |
145 |
| - } |
146 |
| - |
| 102 | + MeterBinder virtualThreadMetrics() throws ClassNotFoundException { |
| 103 | + Class<?> clazz = ClassUtils.forName(VIRTUAL_THREAD_METRICS_CLASS, getClass().getClassLoader()); |
| 104 | + return (MeterBinder) BeanUtils.instantiateClass(clazz); |
147 | 105 | }
|
148 | 106 |
|
149 | 107 | static final class VirtualThreadMetricsRuntimeHintsRegistrar implements RuntimeHintsRegistrar {
|
|
0 commit comments