/** *通过注解方式MBean导出器,继承MBeanExporter */ public class AnnotationMBeanExporter extends MBeanExporter { private final AnnotationJmxAttributeSource annotationSource = new AnnotationJmxAttributeSource(); private final MetadataNamingStrategy metadataNamingStrategy = new MetadataNamingStrategy(this.annotationSource); private final MetadataMBeanInfoAssembler metadataAssembler = new MetadataMBeanInfoAssembler(this.annotationSource); public AnnotationMBeanExporter() { // 设置Naming策略 setNamingStrategy(this.metadataNamingStrategy); //设置metadata组装器 setAssembler(this.metadataAssembler); // 自动检测所有 setAutodetectMode(AUTODETECT_ALL); } }
/** * JmxAttributeSource接口的实现类,它读取注解同时导出相应的属性 * */ public class AnnotationJmxAttributeSource implements JmxAttributeSource { // 获取管理资源 public ManagedResource getManagedResource(Class<?> beanClass) throws InvalidMetadataException { // 获取beanClass上的ManagedResource注解 org.springframework.jmx.export.annotation.ManagedResource ann = beanClass.getAnnotation(org.springframework.jmx.export.annotation.ManagedResource.class); if (ann == null) { return null; } //创建一个ManagedResource ManagedResource managedResource = new ManagedResource(); // 复制属性 AnnotationBeanUtils.copyPropertiesToBean(ann, managedResource); // 如果注解的value()值不为空且ManangedResource的objectName属性长度为空,则将ObjectName设置为value if (!"".equals(ann.value()) && !StringUtils.hasLength(managedResource.getObjectName())) { managedResource.setObjectName(ann.value()); } // 返回 managedResource return managedResource; } // 获取管理属性 public ManagedAttribute getManagedAttribute(Method method) throws InvalidMetadataException { // 获取当前方法上的ManagedAttribute注解 org.springframework.jmx.export.annotation.ManagedAttribute ann = AnnotationUtils.findAnnotation(method, org.springframework.jmx.export.annotation.ManagedAttribute.class); if (ann == null) { return null; } ManagedAttribute managedAttribute = new ManagedAttribute(); AnnotationBeanUtils.copyPropertiesToBean(ann, managedAttribute, "defaultValue"); // 如果ManagedAttribute注解的默认值不为空则设置默认值 if (ann.defaultValue().length() > 0) { managedAttribute.setDefaultValue(ann.defaultValue()); } return managedAttribute; } // 获取ManagedMetric public ManagedMetric getManagedMetric(Method method) throws InvalidMetadataException { org.springframework.jmx.export.annotation.ManagedMetric ann = AnnotationUtils.findAnnotation(method, org.springframework.jmx.export.annotation.ManagedMetric.class); if (ann == null) { return null; } ManagedMetric managedMetric = new ManagedMetric(); AnnotationBeanUtils.copyPropertiesToBean(ann, managedMetric); return managedMetric; } // 获取管理操作 public ManagedOperation getManagedOperation(Method method) throws InvalidMetadataException { Annotation ann = AnnotationUtils.findAnnotation(method, org.springframework.jmx.export.annotation.ManagedOperation.class); if (ann == null) { return null; } ManagedOperation op = new ManagedOperation(); AnnotationBeanUtils.copyPropertiesToBean(ann, op); return op; } // 获取管理操作的参数 public ManagedOperationParameter[] getManagedOperationParameters(Method method) throws InvalidMetadataException { ManagedOperationParameters params = AnnotationUtils.findAnnotation(method, ManagedOperationParameters.class); ManagedOperationParameter[] result = null; if (params == null) { result = new ManagedOperationParameter[0]; } else { Annotation[] paramData = params.value(); result = new ManagedOperationParameter[paramData.length]; for (int i = 0; i < paramData.length; i++) { Annotation annotation = paramData[i]; ManagedOperationParameter managedOperationParameter = new ManagedOperationParameter(); AnnotationBeanUtils.copyPropertiesToBean(annotation, managedOperationParameter); result[i] = managedOperationParameter; } } return result; } // 获取管理通知 public ManagedNotification[] getManagedNotifications(Class<?> clazz) throws InvalidMetadataException { // 获取当前类的ManangedNotifications注解 ManagedNotifications notificationsAnn = clazz.getAnnotation(ManagedNotifications.class); if(notificationsAnn == null) { return new ManagedNotification[0]; } // 获取当前注解的值 Annotation[] notifications = notificationsAnn.value(); ManagedNotification[] result = new ManagedNotification[notifications.length]; // 遍历注解 for (int i = 0; i < notifications.length; i++) { Annotation notification = notifications[i]; ManagedNotification managedNotification = new ManagedNotification(); AnnotationBeanUtils.copyPropertiesToBean(notification, managedNotification); result[i] = managedNotification; } return result; } }
相关推荐
Spring框架本身并不绑定到特定的日志实现,而是通过`spring-context-support.jar`中的`org.springframework.jmx.export.annotation.AnnotationMBeanExporter`类提供对各种日志系统的支持。在实际项目中,根据需求...
2018-05-07 10:33:54.021 INFO 9640 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Bean with name 'dataSource' has been autodetected for JMX exposure 2018-05-07 10:33:54.026 INFO 9640 --- [ main] o.s.j...
那些年,与你同分同位次的同学都去了哪里?全国各大学在辽宁2020-2024年各专业最低录取分数及录取位次数据,高考志愿必备参考数据
ADC建模,ADC数字校准,模拟ic设计 模数转器, ADC MATLAB建模, 包含实例和说明 ADC数字校准 三种adc建模资料打包价格 ,simulink模型 14bit 100MSAR ADC 12位流水线 pipelined ADC sigma-delta adc 模拟IC,ADC建模 多种sar adc和流水线的matlab模型 ADC的动态fft,静态特性inl、dnl仿真 多种 sarADCMATLAB和simulink 建模全都整合在里面了 实用SAR ADC的Matlab Simulink Model,可用于非理想效应的行为级仿真一个实用的SAR ADC的行为级模型。 对多种非理想效应都进行了建模仿真,包括非线性采样,比较器offset,以及电容适配 ADC的动态fft,静态特性inl、dnl仿真 教程,动态静态参数分析。 东西很多,就不一一介绍了。
那些年,与你同分同位次的同学都去了哪里?全国各大学在辽宁2020-2024年各专业最低录取分数及录取位次数据,高考志愿必备参考数据
那些年,与你同分同位次的同学都去了哪里?全国各大学在辽宁2020-2024年各专业最低录取分数及录取位次数据,高考志愿必备参考数据
数据手册-DAC0832-datasheet.zip
数据手册-PL-2303HX-datasheet.zip
那些年,与你同分同位次的同学都去了哪里?全国各大学在辽宁2020-2024年各专业最低录取分数及录取位次数据,高考志愿必备参考数据
2024-10-05 20_42_57-1d975af1.mp3
该源码是一款基于Spring Boot和若依框架构建的企业级能源管理系统,包含1565个文件,其中Java文件800个,Vue文件326个,JavaScript文件150个。系统支持Java、Vue、JavaScript、HTML、Shell等多种编程语言。系统适用于企业、园区、工商业等场景,通过物联网技术实时采集水、电、气、热等能耗数据,帮助企业建立完善的能源管理体系。此外,系统还支持碳跟踪、碳盘查、碳交易、碳汇报等功能,助力企业实现碳中和目标,为中国碳达峰-碳中和贡献力量。
那些年,与你同分同位次的同学都去了哪里?全国各大学在辽宁2020-2024年各专业最低录取分数及录取位次数据,高考志愿必备参考数据
本项目是一款融合JavaScript与Python语言的wdck兴趣爱好项目设计源码,包含64个文件,涵盖32个JavaScript文件、14个JSON文件、8个TXT文件、3个JAR文件、3个GZ文件、1个LICENSE文件、1个MD文件、1个MD5文件和1个PY文件。该项目旨在为用户提供一个丰富多彩的兴趣爱好平台,让用户乐在其中。
数据手册-74HC02-datasheet.zip
酒店管理系统 毕业设计 源码+数据库+论文(JAVA+SpringBoot+Vue.JS) 启动教程:https://www.bilibili.com/video/BV11ktveuE2d
锻压成型机_三维3D设计图纸.zip
该项目为基于Twisted框架开发的2D网络应用设计源码,共包含40个文件,其中包含22个Python源代码文件,9个用于示例的POSCAR文件,以及相应的其他文件类型,如JSON、LICENSE、Markdown等。该项目可从GitHub上的Twisted2D仓库获取。
自动打螺丝机_三维3D设计图纸.zip
滴答拍摄影项目 毕业设计 源码+数据库+论文(JAVA+SpringBoot+Vue.JS) 启动教程:https://www.bilibili.com/video/BV11ktveuE2d
用python裁剪txt的代码