普通web工程加入Spring任务的支持
2013-03-01 21:53
197 查看
普通的web工程,不支持Spring,我们需要执行定时任务,那么步骤如下:步骤1:Spring的支持,在web.xml中引入Spring的contextJava代码
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
同时加入Spring的配置文件路径信息Xml代码
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-*.xml</param-value>
</context-param>
步骤2:Spring支持Task和注解(注解的形式)Java代码
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:task="http://www.springframework.org/schema/task" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p" xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
xmlns:beans="http://www.springframework.org/schema/beans" xmlns:device="http://www.springframework.org/schema/mobile/device"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-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/task
http://www.springframework.org/schema/task/spring-task-3.0.xsd">
步骤3:开发调度任务Java代码
@Service("cacheInvokeJob")
public class CacheInvokeJob {
/**
* This method is demo
*/
public void demo() {
//你的业务操作
}
}
步骤4:设定调度cron
Java代码
<mvc:annotation-driven />
<context:component-scan base-package="com.test.web.job" />
<task:scheduled-tasks>
<task:scheduled ref="cacheInvokeJob" method="demo"
cron="0 10 22 * * ?" />
</task:scheduled-tasks>
现在ok,可以正常执行了
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
同时加入Spring的配置文件路径信息Xml代码
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-*.xml</param-value>
</context-param>
步骤2:Spring支持Task和注解(注解的形式)Java代码
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:task="http://www.springframework.org/schema/task" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p" xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
xmlns:beans="http://www.springframework.org/schema/beans" xmlns:device="http://www.springframework.org/schema/mobile/device"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-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/task
http://www.springframework.org/schema/task/spring-task-3.0.xsd">
步骤3:开发调度任务Java代码
@Service("cacheInvokeJob")
public class CacheInvokeJob {
/**
* This method is demo
*/
public void demo() {
//你的业务操作
}
}
步骤4:设定调度cron
Java代码
<mvc:annotation-driven />
<context:component-scan base-package="com.test.web.job" />
<task:scheduled-tasks>
<task:scheduled ref="cacheInvokeJob" method="demo"
cron="0 10 22 * * ?" />
</task:scheduled-tasks>
现在ok,可以正常执行了
相关文章推荐
- Hibernate基础之给java web工程加入Hibernate支持
- Spring 定时任务(精)(session工具类(配置失效时间),cookie工具类 web工程(初始化容器) redis工具类)
- spring在web工程和普通java工程使用时候区别
- 为web工程添加struts、hibernate和spring支持(eclipse)
- web项目中加入struts2、spring的支持,并整合两者
- spring session + redis 实现web工程的session共享
- 在Web工程中加入favicon.ico
- java 利用spring JavaMailSenderImpl发送邮件,支持普通文本、附件、html、velocity模板
- 使用Spring做定时任务工程
- Maven4MyEclipse 搭建ssh2+extjs项目(3)加入spring支持
- java 利用spring JavaMailSenderImpl发送邮件,支持普通文本、附件、html、velocity模板
- Spring 获取web根目录 (Spring线程获取web目录/路径/根目录,普通类获取web目录)
- Spring Boot工程支持HTTP和HTTPS,HTTP重定向HTTPS
- idea2017.2普通web工程将lib包导入到artifact中
- InstallShield 2012 Spring新功能试用(15): Suite/Advanced UI 和 Advanced UI工程支持动态链接安装包文件
- Spring 多线程bean的问题(Spring+Javaweb中任务调度)
- Spring Web MVC中的页面缓存支持 ——跟我学SpringMVC系列
- Spring web项目使用Quartz定时任务
- web定时任务之spring
- spring boot-高级话题之 多线程、@EnableScheduling开启计划任务的支持(2)