16
16
17
17
package org .springframework .integration .monitor ;
18
18
19
- import org .springframework .beans .annotation .AnnotationBeanUtils ;
19
+ import java .lang .reflect .Modifier ;
20
+ import java .util .ArrayList ;
21
+ import java .util .List ;
22
+ import java .util .Map ;
23
+
24
+ import org .springframework .beans .MutablePropertyValues ;
25
+ import org .springframework .beans .PropertyAccessorFactory ;
26
+ import org .springframework .beans .PropertyValue ;
20
27
import org .springframework .beans .factory .BeanFactory ;
21
28
import org .springframework .beans .factory .config .ConfigurableBeanFactory ;
22
29
import org .springframework .beans .factory .config .EmbeddedValueResolver ;
23
- import org .springframework .core .annotation .AnnotationUtils ;
30
+ import org .springframework .core .annotation .MergedAnnotation ;
31
+ import org .springframework .core .annotation .MergedAnnotations ;
24
32
import org .springframework .integration .support .management .IntegrationManagedResource ;
25
33
import org .springframework .jmx .export .annotation .AnnotationJmxAttributeSource ;
26
34
import org .springframework .jmx .export .metadata .InvalidMetadataException ;
33
41
*
34
42
* @author Gary Russell
35
43
* @author Artem Bilan
44
+ *
36
45
* @since 4.3
37
46
*/
38
47
public class IntegrationJmxAttributeSource extends AnnotationJmxAttributeSource {
39
48
40
49
private StringValueResolver valueResolver ;
41
50
42
- public void setValueResolver (StringValueResolver valueResolver ) {
43
- this .valueResolver = valueResolver ;
44
- }
45
-
46
51
@ Override
47
52
public void setBeanFactory (BeanFactory beanFactory ) {
48
53
super .setBeanFactory (beanFactory );
@@ -53,13 +58,34 @@ public void setBeanFactory(BeanFactory beanFactory) {
53
58
54
59
@ Override
55
60
public ManagedResource getManagedResource (Class <?> beanClass ) throws InvalidMetadataException {
56
- IntegrationManagedResource ann = AnnotationUtils .getAnnotation (beanClass , IntegrationManagedResource .class );
57
- if (ann == null ) {
61
+ MergedAnnotation <IntegrationManagedResource > ann =
62
+ MergedAnnotations .from (beanClass , MergedAnnotations .SearchStrategy .EXHAUSTIVE )
63
+ .get (IntegrationManagedResource .class )
64
+ .withNonMergedAttributes ();
65
+ if (!ann .isPresent ()) {
58
66
return null ;
59
67
}
60
- ManagedResource managedResource = new ManagedResource ();
61
- AnnotationBeanUtils .copyPropertiesToBean (ann , managedResource , this .valueResolver );
62
- return managedResource ;
68
+ Class <?> declaringClass = (Class <?>) ann .getSource ();
69
+ Class <?> target = (declaringClass != null && !declaringClass .isInterface () ? declaringClass : beanClass );
70
+ if (!Modifier .isPublic (target .getModifiers ())) {
71
+ throw new InvalidMetadataException ("@IntegrationManagedResource class '" + target .getName () +
72
+ "' must be public" );
73
+ }
74
+
75
+ ManagedResource bean = new ManagedResource ();
76
+ Map <String , Object > map = ann .asMap ();
77
+ List <PropertyValue > list = new ArrayList <>(map .size ());
78
+ map .forEach ((attrName , attrValue ) -> {
79
+ if (!"value" .equals (attrName )) {
80
+ Object value = attrValue ;
81
+ if (this .valueResolver != null && value instanceof String ) {
82
+ value = this .valueResolver .resolveStringValue ((String ) value );
83
+ }
84
+ list .add (new PropertyValue (attrName , value ));
85
+ }
86
+ });
87
+ PropertyAccessorFactory .forBeanPropertyAccess (bean ).setPropertyValues (new MutablePropertyValues (list ));
88
+ return bean ;
63
89
}
64
90
65
91
}
0 commit comments