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

}

spring-初始化bean的更多相关文章

  1. Spring初始化Bean或销毁Bean前执行操作的方式

    如果想在Spring初始化后,或者销毁前做某些操作,常用的设定方式有三种: 第一种:通过 在xml中定义init-method 和 destory-method方法 推荐使用,缺陷是只能在XML中使用 ...

  2. spring初始化bean的目的

    初始化bean就是为了将所有需要的bean全部装载到容器里面,等我们需要用到哪个bean就将哪个bean从容器里面拿出来

  3. InitializingBean,spring 初始化bean

    springframework的提供接口,InitializingBean接口为bean提供了初始化方法的方式,它只包括afterPropertiesSet方法,凡是继承该接口的类,在初始化bean的 ...

  4. spring初始化bean时执行某些方法完成特定的初始化操作

    在项目中经常会在容器启动时,完成特定的初始化操作,如资源文件的加载等. 一 实现的方式有三种: 1.使用@PostConstruct注解,该注解作用于void方法上 2.在配置文件中配置init-me ...

  5. spring的初始化bean,销毁bean之前的操作详解

    我所知道的在spring初始化bean,销毁bean之前的操作有三种方式: 第一种:通过@PostConstruct 和 @PreDestroy 方法 实现初始化和销毁bean之前进行的操作 第二种是 ...

  6. Spring 的 Bean 管理(注解方式)

    Spring 的 Bean 管理(注解方式) 1. 导入必要的 jar 包和 xml 文件 使用注解需要导入 spring-aop 的 jar 包. applicationContext.xml 文件 ...

  7. spring初始化源码浅析之关键类和扩展接口

    目录 1.关键接口和类 1.1.关键类之 DefaultListableBeanFactory 1.2.关键类之XmlBeanDefinitionReader 1.3.关键类之ClassPathXml ...

  8. Web.xml配置详解之context-param (加载spring的xml,然后初始化bean看的)

    http://www.cnblogs.com/goody9807/p/4227296.html(很不错啊) 容器先加载spring的xml,然后初始化bean时,会为bean赋值,包括里面的占位符

  9. Spring 基础知识(二)Spring的bean初始化与生命周期,以及注入

    Spring bean 初始化: 参考博文: https://www.cnblogs.com/luyanliang/p/5567164.html 1. 加载xml 文件. 扫描注解 ,形成bean定义 ...

  10. Spring中初始化bean和销毁bean的时候执行某个方法的详解

    关于在spring  容器初始化 bean 和销毁前所做的操作定义方式有三种: 第一种:通过注解@PostConstruct  和 @PreDestroy 方法 实现初始化和销毁bean之前进行的操作 ...

随机推荐

  1. shell基础之书写需要用到的小工具

    一.简单介绍 下面介绍几个可能不太常用但是面试题经常会用用到的小工具: 命令:cut 作用:截取某一个字段 '-d' 后面跟分隔字符,把字段分割为若干个区间. '-c' 后面接的是第几个字符,也可以是 ...

  2. 设置浏览器地址栏URL前面显示的图标

    其实很简单,你只做个ico图标,命名为favicon.ico,把它传到你的页面下面. 并在相应的页面里加上代码  在页面<heah></heah>之间加, <link r ...

  3. review01

    .java叫源文件,java编译器编译源文件后会产生字节码文件,java解释器将字节码文件加载进内存,java虚拟机来执行字节码文件. 如下列文件名为“String01.java” public cl ...

  4. Django-03

    知识预览 分页器(paginator) COOKIE 与 SESSION Django的用户认证 FORM 回到顶部 分页器(paginator) 分页器的使用 1 2 3 4 5 6 7 8 9 1 ...

  5. Tomcat翻译--The Host Container

    原文:http://tomcat.apache.org/tomcat-7.0-doc/config/host.html Introduction(介绍) The Host element repres ...

  6. asp.net上传文件大小限制

    <system.webServer> <security> <requestFiltering> <requestLimits maxAllowedConte ...

  7. JProfiler连接weblogic

    转 http://blog.csdn.net/xu1314/article/details/7737236

  8. Django-进阶

    分页 Django的分页器(paginator) view from django.shortcuts import render,HttpResponse # Create your views h ...

  9. stencil in unity3d

    Pass { Stencil { Ref Comp Always Pass REPLACE } AlphaTest Greater Blend SrcAlpha OneMinusSrcAlpha Co ...

  10. 通过ifreme实现文件上传

    模板页面添加ifreme <div style=' display: none;' >      <iframe name ="uploadResponse_attachm ...