spring+InitializingBean+quartz+定时器


下面会给出文件链接,以下只说如何调用 文件名为例

InitializingBean:为bean提供了初始化,初始化bean的时候都会执行方法(afterPropertiesSet)
quartz:用于定时调度

<dependency>
	<groupId>org.quartz-scheduler</groupId>
	<artifactId>quartz</artifactId>
	<version>2.2.1</version>
</dependency>
<dependency>
	<groupId>org.quartz-scheduler</groupId>
	<artifactId>quartz-jobs</artifactId>
	<version>2.2.1</version>
</dependency>

web.xml 配置:

<servlet> <servlet-name>springmvc</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring-mvc.xml </param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>springmvc</servlet-name> <url-pattern>*.action</url-pattern> </servlet-mapping>

spring-mvc 配置:

<bean id="InitDataListener" class="cn.fulong.web.workApproval.utils.InitDataListener"></bean>

InitDataListener.java

package cn.fulong.web.workApproval.utils; import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; /** * java类简单作用描述 * @ProjectName: oa * @Package: cn.fulong.web.workApproval.utils * @ClassName: InitDataListener * @Description: java类作用描述 * @Author: yu_du_chen * @CreateDate: 2019/7/25 9:55 * @Version: 1.0 */ @Service @Lazy(value=false) //必须关闭懒加载 public class InitDataListener implements InitializingBean { @Autowired private QuartzManager quartzManager; @Override public void afterPropertiesSet() throws Exception { System.out.println("afterPropertiesSet加载成功"); quartzManager.addJob("start", "start", "start", "start", MyJob.class, "0 0 6 ? * *",""); } } QuartzManager工具类 密码:mr5k MyJob 定时器 密码:updz
posted @ 2019-07-25 12:01  羽渡尘  阅读(195)  评论(0编辑  收藏  举报