@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. keystone cache

    http://docs.openstack.org/juno/config-reference/content/section_keystone.conf.html http://docs.opens ...

  2. c# 查找一个字符串在另一个字符串出现的次数

    方法一: string test = "FF FF FF FF 01 00 82 00 00 A2 00 00 FB 07 FF FF FF FF 01 00 82 00 00 A2 00 ...

  3. js dom操作选择器,dom操作复习

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  4. sublime text配置编译C#环境

    参照:http://www.cnblogs.com/Bob-wei/p/4670341.html 添加C#支持(Windows)  1) 配置环境变量 Path     C# 6.0编译器:可以将cs ...

  5. CentOS7下Tomcat启动特别慢【有效解决】

    多次亲测! 很简单,记录保存一下: 编辑 $JAVA_HOME/jre/lib/security/java.security 文件, 找到 securerandom.source=file:/dev/ ...

  6. 炫酷tab栏--第三方开源--NavigationTabStrip

    github下载地址:https://github.com/DevLight-Mobile-Agency/NavigationTabStrip 这个开源项目很强大,只是一个自定义的控件,只有一个类 / ...

  7. 唯一id UUID

    public static String getUUID() { String s = UUID.randomUUID().toString(); return s.substring(0, 8) + ...

  8. MySQL分片 --转自Peter Zaitsev对MySQL分片的建议

    本文作者Peter Zaitsev是知名数据库专家,2006年联合创立了Percona.负责维护网站“MySQL性能”.同时,他也是<高性能MySQL>一书的联合作者.以下是他对MySQL ...

  9. L115

    The reasons of reading books - part I1. You will optimize your brain powerThis shouldn't come as a s ...

  10. UVA 11988 Broken Keyboard (a.k.a. Beiju Text) (链表,模拟)

    使用list来模拟就行了,如果熟悉list,那么这道题真是分分钟秒掉... list是双向循环链表,插入和删除操作非常快,缺点是不能像数组一样随机按下标读取. 一下是wiki上说明的相关函数:http ...