1616
1717package org .springframework .integration .monitor ;
1818
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 ;
2027import org .springframework .beans .factory .BeanFactory ;
2128import org .springframework .beans .factory .config .ConfigurableBeanFactory ;
2229import 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 ;
2432import org .springframework .integration .support .management .IntegrationManagedResource ;
2533import org .springframework .jmx .export .annotation .AnnotationJmxAttributeSource ;
2634import org .springframework .jmx .export .metadata .InvalidMetadataException ;
3341 *
3442 * @author Gary Russell
3543 * @author Artem Bilan
44+ *
3645 * @since 4.3
3746 */
3847public class IntegrationJmxAttributeSource extends AnnotationJmxAttributeSource {
3948
4049 private StringValueResolver valueResolver ;
4150
42- public void setValueResolver (StringValueResolver valueResolver ) {
43- this .valueResolver = valueResolver ;
44- }
45-
4651 @ Override
4752 public void setBeanFactory (BeanFactory beanFactory ) {
4853 super .setBeanFactory (beanFactory );
@@ -53,13 +58,34 @@ public void setBeanFactory(BeanFactory beanFactory) {
5358
5459 @ Override
5560 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 ()) {
5866 return null ;
5967 }
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 ;
6389 }
6490
6591}
0 commit comments