• 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);
    }

    }

  • 相关阅读:
    [LeetCode] 134. Gas Station Java
    [LeetCode] 22. Best Time to Buy and Sell Stock II Java
    [LeetCode] 55. Jump Game Java
    [LeetCode] 264. Ugly Number II Java
    [LeetCode] 331. Verify Preorder Serialization of a Binary Tree Java
    [LeetCode] 232. Implement Queue using Stacks Java
    java.lang.ClassNotFoundException: org.apache.juli.logging.LogFactory的解决办法
    Linux centos 连接网络
    MyEclipse默认编码为GBK,修改为UTF8的方法
    表单
  • 原文地址:https://www.cnblogs.com/wlhebut/p/6420089.html
Copyright © 2020-2023  润新知