当前位置: 首页 > news >正文

使用Spring的getBeansOfType实现接口多实现类的动态调用

使用Spring的getBeansOfType实现接口多实现类的动态调用

package com.xxl.job.admin.core.alarm;import com.xxl.job.admin.core.model.XxlJobInfo;
import com.xxl.job.admin.core.model.XxlJobLog;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;import java.util.ArrayList;
import java.util.List;
import java.util.Map;@Component
public class JobAlarmer implements ApplicationContextAware, InitializingBean {private static Logger logger = LoggerFactory.getLogger(JobAlarmer.class);private ApplicationContext applicationContext;private List<JobAlarm> jobAlarmList;@Overridepublic void setApplicationContext(ApplicationContext applicationContext) throws BeansException {this.applicationContext = applicationContext;}@Overridepublic void afterPropertiesSet() throws Exception {Map<String, JobAlarm> serviceBeanMap = applicationContext.getBeansOfType(JobAlarm.class);if (serviceBeanMap != null && serviceBeanMap.size() > 0) {jobAlarmList = new ArrayList<JobAlarm>(serviceBeanMap.values());}}/*** job alarm** @param info* @param jobLog* @return*/public boolean alarm(XxlJobInfo info, XxlJobLog jobLog) {boolean result = false;if (jobAlarmList!=null && jobAlarmList.size()>0) {result = true;  // success means all-successfor (JobAlarm alarm: jobAlarmList) {boolean resultItem = false;try {resultItem = alarm.doAlarm(info, jobLog);} catch (Exception e) {logger.error(e.getMessage(), e);}if (!resultItem) {result = false;}}}return result;}}
http://www.lryc.cn/news/149011.html

相关文章:

  • (笔记三)opencv图像基础操作
  • PHP入门及环境搭建 - XAMPP
  • 开学季ipad手写笔什么牌子好?第三方电容笔推荐
  • 【力扣】62. 不同路径 <动态规划>
  • 【Python小项目】Python的GUI库Tkinter实现随机点名工具或抽奖工具并封装成.exe可执行文件
  • 【MySql】mysql之基础语句
  • 使用API调用获取商品数据的完整方案
  • 来看看入门级别的室内设计创意是怎么样构成的
  • Go 面向对象(匿名字段)
  • 生成式AI,赋能数字劳动力的关键工具
  • python提取邮件的附件,以excel为例
  • ZooKeeper技术内幕
  • 乱糟糟的YOLOv8-detect和pose训练自己的数据集
  • 【Nginx】Nginx $remote_addr和$proxy_add_x_forwarded_for变量详解
  • MySQL自动删除binlog日志
  • C++ 文件和流
  • 案例分享:西河水库安全监测信息化系统实施方案
  • 使用Angular和MongoDB来构建具有登录功能的博客应用程序
  • ChatGPT 与前端技术实现制作大屏可视化
  • 视频监控/视频云存储EasyCVR平台接入华为ivs3800平台提示400报错,如何解决?
  • c++基础数据结构
  • 微服务-sentinel详解
  • 【MTK平台】根据kernel log分析wifi 连接的时候流程
  • 【SpringBoot】两种配置文件, 详解 properties 和 yml 的语法格式, 使用方式, 读取配置
  • 基于微信小程序的文化宣传平台的设计与实现(Java+spring boot+微信小程序+MySQL)
  • 一款windows的终端神奇,类似mac的iTem2
  • illegal cyclic inheritance involving trait Iterable_2种解决方式
  • 探秘二叉树后序遍历:从叶子到根的深度之旅
  • 2023全国大学生数学建模A题思路+模型+代码+论文(比赛开始后持续更新)
  • 从输入URL到页面展示过程:深入解析网络请求与渲染