16
16
17
17
package org .springframework .boot .autoconfigure .integration ;
18
18
19
+ import javax .management .MBeanServer ;
20
+
21
+ import org .springframework .beans .BeansException ;
22
+ import org .springframework .beans .factory .BeanFactory ;
23
+ import org .springframework .beans .factory .BeanFactoryAware ;
24
+ import org .springframework .beans .factory .annotation .Autowired ;
25
+ import org .springframework .beans .factory .annotation .Qualifier ;
19
26
import org .springframework .boot .autoconfigure .AutoConfigureAfter ;
20
27
import org .springframework .boot .autoconfigure .condition .ConditionalOnClass ;
21
28
import org .springframework .boot .autoconfigure .condition .ConditionalOnMissingBean ;
22
29
import org .springframework .boot .autoconfigure .condition .ConditionalOnProperty ;
23
30
import org .springframework .boot .autoconfigure .condition .SearchStrategy ;
24
31
import org .springframework .boot .autoconfigure .jmx .JmxAutoConfiguration ;
32
+ import org .springframework .boot .bind .RelaxedPropertyResolver ;
33
+ import org .springframework .context .EnvironmentAware ;
34
+ import org .springframework .context .annotation .Bean ;
25
35
import org .springframework .context .annotation .Configuration ;
36
+ import org .springframework .context .annotation .Primary ;
37
+ import org .springframework .core .env .Environment ;
26
38
import org .springframework .integration .config .EnableIntegration ;
27
39
import org .springframework .integration .jmx .config .EnableIntegrationMBeanExport ;
28
40
import org .springframework .integration .monitor .IntegrationMBeanExporter ;
41
+ import org .springframework .integration .support .management .IntegrationManagementConfigurer ;
42
+ import org .springframework .util .StringUtils ;
29
43
30
44
/**
31
45
* {@link org.springframework.boot.autoconfigure.EnableAutoConfiguration
@@ -50,8 +64,49 @@ protected static class IntegrationConfiguration {
50
64
@ ConditionalOnClass (EnableIntegrationMBeanExport .class )
51
65
@ ConditionalOnMissingBean (value = IntegrationMBeanExporter .class , search = SearchStrategy .CURRENT )
52
66
@ ConditionalOnProperty (prefix = "spring.jmx" , name = "enabled" , havingValue = "true" , matchIfMissing = true )
53
- @ EnableIntegrationMBeanExport (defaultDomain = "${spring.jmx.default-domain:}" , server = "${spring.jmx.server:mbeanServer}" )
54
- protected static class IntegrationJmxConfiguration {
67
+ protected static class IntegrationJmxConfiguration implements EnvironmentAware , BeanFactoryAware {
68
+
69
+ private BeanFactory beanFactory ;
70
+
71
+ private RelaxedPropertyResolver propertyResolver ;
72
+
73
+ @ Autowired (required = false )
74
+ @ Qualifier (IntegrationManagementConfigurer .MANAGEMENT_CONFIGURER_NAME )
75
+ private IntegrationManagementConfigurer configurer ;
76
+
77
+ @ Override
78
+ public void setBeanFactory (BeanFactory beanFactory ) throws BeansException {
79
+ this .beanFactory = beanFactory ;
80
+ }
81
+
82
+ @ Override
83
+ public void setEnvironment (Environment environment ) {
84
+ this .propertyResolver = new RelaxedPropertyResolver (environment , "spring.jmx." );
85
+ }
86
+
87
+ @ Bean
88
+ @ Primary
89
+ public IntegrationMBeanExporter integrationMbeanExporter () {
90
+ IntegrationMBeanExporter exporter = new IntegrationMBeanExporter ();
91
+ String defaultDomain = this .propertyResolver .getProperty ("default-domain" );
92
+ if (StringUtils .hasLength (defaultDomain )) {
93
+ exporter .setDefaultDomain (defaultDomain );
94
+ }
95
+ String server = this .propertyResolver .getProperty ("server" , "mbeanServer" );
96
+ if (StringUtils .hasLength (server )) {
97
+ exporter .setServer (this .beanFactory .getBean (server , MBeanServer .class ));
98
+ }
99
+ if (this .configurer != null ) {
100
+ if (this .configurer .getDefaultCountsEnabled () == null ) {
101
+ this .configurer .setDefaultCountsEnabled (true );
102
+ }
103
+ if (this .configurer .getDefaultStatsEnabled () == null ) {
104
+ this .configurer .setDefaultStatsEnabled (true );
105
+ }
106
+ }
107
+ return exporter ;
108
+ }
109
+
55
110
}
56
111
57
112
}
0 commit comments