好吧..其实是百度的....代码如下
此部分为spring配置器属性
xmlns:task="http://www.springframework.org/schema/task"
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-3.1.xsd
比较纠结的一个问题.因为项目分离等等原因造成定时器启动后dao层注入为null解决办法.重新扫描spring注解
<context:component-scan base-package="com.primecocn.nakri.*"></context:component-scan>
从上到下:
1、task扫描
2、bean注入
3定时器启动
<task:annotation-driven/>
<bean id="QuartProcessService" class="com.primecocn.nakri.settings.service.impl.QuartProcessServiceImpl" >
</bean>
<task:scheduled-tasks>
<task:scheduled ref="QuartProcessService" method="checkRepayPlan" cron="0 0/5 * * * ?"/>
</task:scheduled-tasks>
@Component用来注解定时器
@Component
public class QuartProcessServiceImpl implements QuartProcessService {
public static Logger log = LoggerFactory.getLogger(QuartProcessService.class);
@Autowired
public QuartProcessDao quartProcessDao;
// public QuartProcessServiceImpl() {
// quartProcessDao =(QuartProcessDaoImpl) ApplicationContextUtil.getBean("quartProcessDaoImpl");
// corporationDao = (CorporationDaoImpl) ApplicationContextUtil.getBean("corporationDaoImpl");
//
// }
@Override
public void checkRepayPlan() {
system.out.pring("定时器启动.quartProcessDao是否为null" + quartProcessDao);
}
至此全注解定时器完成...