1. 添加一个接口
l添加一个IExampleMechanismJobService接口,在里面添加一个add方法,如下:
public interface IExampleMechanismJobService extends IBaseService {
//定时添加portlet
public void add() throws Exception;
}
2. 添加一个服务类
l 添加一个ExampleMechanismJobServiceImp服务类,实现IExampleMechanismJobService接口,实现add方法,如下:
public class ExampleMechanismJobServiceImp extends BaseServiceImp implements
IExampleMechanismJobService {
private IExampleMechanismPortletTitleService exampleMechanismPortletTitleService;
public void setExampleMechanismPortletTitleService(
IExampleMechanismPortletTitleService exampleMechanismPortletTitleService) {
this.exampleMechanismPortletTitleService = exampleMechanismPortletTitleService;
}
// 定时添加portlet
public void add() throws Exception {
ExampleMechanismPortletTitle exampleMechanismPortletTitle = new ExampleMechanismPortletTitle();
exampleMechanismPortletTitle.setFdName("定时任务");
exampleMechanismPortletTitle.setFdCreateTime(new Date());
exampleMechanismPortletTitleService.add(exampleMechanismPortletTitle);
}
3. spring中配置service
l 在spring中进行service的配置,如下:
<bean
id="exampleMechanismJobService"
parent="KmssBaseService"
class="com.landray.kmss.example.mechanism.service.spring.ExampleMechanismJobService Imp"
<property name="exampleMechanismPortletTitleService ">
<ref local=" exampleMechanismPortletTitleService " />
</property>
</bean>
4. design中配置quartz属性
l 在design中配置quartz属性,如下:
<quartz
messageKey="example-mechanism:exampleMechanismPortletTitle.quartz"
<!--定时任务的名称,需要在资源文件里面配置-->
jobService="exampleMechanismJobService"
<!--spring里面配置的定时任务的service名称-->
cronExpression="0 0 1 * * ?"
<!--执行时间和频率-->
jobMethod="add" />
<!—执行方法-->