• spring-初始化bean


    @EnableScheduling
    @Service
    public class BaseTask implements InitializingBean, ApplicationContextAware{
    private final static Logger viewLogger = LoggerFactory.getLogger(BaseTask.class);
    public static final int HOURPERDATE=24;
    public static final String DATABASETABLES="ibms2";
    public static final String DATABASEBEGINWITH="sgly";
    public static final String DATABASEENDWITH="01";

    @Autowired
    private EquipmentService equipmentService;
    private HashMap<String, Equipment> equipmentsMap = new HashMap<String, Equipment>();
    List<String> ibms2TableNames =new ArrayList<String>();//存储表名

    public static final String DRIVER_CLASS = "com.mysql.jdbc.Driver";
    public static final String URL = "jdbc:mysql://10.5.210.101:3306/ibms2";
    public static final String USERNAME = "root";
    public static final String PASSWORD = "Zaq!2wsx";


    /*"30 10 1 * * ?" 每天1点10分30秒触发任务
    * //@Scheduled(cron="30 * * * * ?")
    * */

    @Scheduled(cron="30 55 13 * * ?")
    @Transactional
    public void run(){


    //定时调用存储过程
    String sql="{CALL p_simulate_dynamic_cursor()}";
    try {
    Connection connection = DriverManager.getConnection(URL, USERNAME, PASSWORD);
    CallableStatement prepareCall = connection.prepareCall(sql);//可以设置参数
    prepareCall.execute();//执行存储过程。
    viewLogger.info("CALL p_simulate_dynamic_cursor()执行完毕");
    prepareCall.close();
    connection.close();
    } catch (SQLException e) {
    e.printStackTrace();
    }
    }

    @Override
    public void afterPropertiesSet() throws Exception {
    equipmentsMap = new HashMap<String,Equipment>();
    Iterable<Equipment> equipmentsIterator = equipmentService.findAll();
    for (Equipment equipment : equipmentsIterator) {
    if(!equipmentsMap.containsKey(equipment)){
    equipmentsMap.put(equipment.getEquid(), equipment);
    }
    }

    }

    @Override
    public void setApplicationContext(ApplicationContext arg0) throws BeansException {
    AppServiceHelper.setApplicationContext(arg0);
    }

    }

  • 相关阅读:
    elasticsearch的rest搜索---mapping
    elasticsearch的rest搜索--- 安装
    elasticsearch的rest搜索--- 总述
    vs2012代码段,快捷键,snippet 的使用
    Web字体@font-face对于中文字体的使用
    对于VS相关的插件
    作业九 ——报告及总结
    结对编程项目——四则运算
    代码规范、代码复审、PSP
    源程序版本管理软件和项目管理软件
  • 原文地址:https://www.cnblogs.com/wlhebut/p/6420089.html
Copyright © 2020-2023  润新知