zoukankan      html  css  js  c++  java
  • 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);
    }

    }

  • 相关阅读:
    AOP面向切面编程
    java中与运算,或运算,异或运算,取反运算
    Java中replace和replaceall的区别
    Satisfying memory ordering requirements between partial reads and non-snoop accesses
    JS判断字符串中是否存在某个字符
    PHP 简介
    PHP 是什么
    mysql substr() 函数
    MySQL 数学函数
    MySQL 字符串截取SUBSTRING()函数
  • 原文地址:https://www.cnblogs.com/wlhebut/p/6420089.html
Copyright © 2011-2022 走看看