1.spring-listener:

a)

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

public class ServletImpl implements ServletContextListener {

@Override
public void contextInitialized(ServletContextEvent sce) {
// TODO Auto-generated method stub

System.out.println("web启动的时候调用此类********************************************************");
}

@Override
public void contextDestroyed(ServletContextEvent sce) {
// TODO Auto-generated method stub
System.out.println("webdestroy的时候调用此类********************************************************");

}

}

b)web.xml配置

<!-- 自定义监听器 -->
<listener>
<listener-class>com.servlet.impl.ServletImpl</listener-class>
</listener>

经过上边简单的两部操作,即可实现web容器启动时候执行某个动作。

2.spring-task

a)task.class,红色标记都是必须的。

import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@EnableScheduling
@Component
public class FooTask {

@Scheduled(cron="0 0/1 8-23 * * ?")
public void run(){
System.out.println("start run...........................................................");
}
}

b)spring.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-3.1.xsd">
<!-- auto scan task -->
<task:annotation-driven/>
<context:annotation-config/>
<bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/>
<context:component-scan base-package="com.task"/>

参考:http://blog.csdn.net/wumingqian_137229/article/details/52846261 感谢分享!

最新文章

  1. javase--&gt;多线程--线程池
  2. &lt;&lt;&lt; ajax在jsp中对于https跨域不能访问
  3. formValidator 表单验证
  4. 字节流和字符流(PrintStream类和PrintWiter类)
  5. numpy.distutils.system_info.NotFoundError: no lapack/blas resources found
  6. 让ie6也支持max-width,和max-height实现图片等比例缩放
  7. Performance Tuning of Spring/Hibernate Applications---reference
  8. 基于visual Studio2013解决C语言竞赛题之0306分数转换
  9. CharSequence的getText()与String的getString()(转)
  10. 基于Nginx+redis的Asp.net站点搭建
  11. %f使用时的注意事项
  12. Redis工作系列之一 与 Memcached对比理解
  13. Day9 基于TCP的套接字和基于UDP的套接字
  14. struts2 学习01
  15. 解决flask中文乱码的问题
  16. pandas数据结构之Dataframe
  17. C# MD5 加密
  18. install docker swarm on centos
  19. 防止sql注入的函数addslashes()
  20. JSP相关知识

热门文章

  1. 源码阅读 etherum-block.py
  2. iOS 自定义键盘ToolBar(与键盘的弹出、收起保持一致)
  3. swiper.animate~之~可以执行两种动画的升级版的Swiper Animate
  4. 后移动互联网时代:到底还要不要开发一个App?
  5. vpn打通结果ping不通
  6. 手机APP开发:学JAVA转安卓APP开发是不是很容易?
  7. ubuntu安装libxml2--PC端
  8. ubuntu安装使用latex和texmaker--PC端
  9. JAVA:通过poi读取excel
  10. 一些有意思的VR设备介绍