In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces the jspXCMS how to develop timing tasks related knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe that everyone after reading this jspXCMS how to develop timing tasks article will have a harvest, let's take a look.
There are scheduled tasks in the system, and there are some task types that have been defined by the system. If the task type that comes with the system does not have its own needs, you can develop a task type.
In line with the idea of non-intrusive secondary development design, it is possible to develop one's own task type without modifying the original code and files of the system.
Scheduled task profile
Jspxcms8.0 and later versions:
/ src/main/resources/conf/conf.properties
Jspxcms6.5-7.5 version:
/ src/main/resources/conf/application.properties
Jspxcms6.0 and previous versions:
/ WEB-INF/conf/application.properties
Related configuration content:
ScheduleJob.100=com.jspxcms.core.quartz.InfoPublishJobscheduleJobPath.com.jspxcms.core.quartz.InfoPublishJob=scheduleJob.200=com.jspxcms.core.quartz.HtmlHomeJobscheduleJobPath.com.jspxcms.core.quartz.HtmlHomeJob=scheduleJob.300=com.jspxcms.ext.quartz.CollectJobscheduleJobPath.com.jspxcms.ext.quartz.CollectJob=/cmscp/ext/collect/schedule_job.do
The configuration of custom scheduled task types can also be written in other conf.properties files, such as / src/main/resources/conf/plugin/plug/conf.properties.
Scheduled task type serial number
ScheduleJob.300: serial number 300 determines the sort of this type, that is, the order before and after the task type is selected. The serial number cannot be repeated.
Scheduled task name
Com.jspxcms.ext.quartz.CollectJob is both a timed task implementation class and a timed task type name. The corresponding internationalization name needs to be defined in the internationalization file.
Internationalized files (Jspxcms6.5 and later): / src/main/resources/messages/ext/ext.properties
Internationalization files (Jspxcms6.0 and previous versions): / WEB-INF/messages/ext/ext.properties
ScheduleJob.code.com.jspxcms.ext.quartz.CollectJob= acquisition
Need to use scheduleJob.code. The beginning. The internationalization name can also be written in other files, such as / src/main/resources/messages/plugin/plug/plug.properties.
Timed task implementation class
Com.jspxcms.ext.quartz.CollectJob is a timed task implementation class.
Public class CollectJob implements Job {private static final Logger logger = LoggerFactory .getLogger (CollectJob.class); public static final String COLLECT_ID = "collectId"; public void execute (JobExecutionContext context) throws JobExecutionException {try {ApplicationContext appContext = (ApplicationContext) context .getScheduler (). GetContext (). Get (Constants.APP_CONTEXT); Collector collector = appContext.getBean (Collector.class) JobDataMap map = context.getJobDetail (). GetJobDataMap (); Integer collectId = map.getIntegerFromString (COLLECT_ID); collector.start (collectId); System.out.println ("collect ok"); logger.info ("run collect job:" + collectId);} catch (SchedulerException e) {throw new JobExecutionException ("Cannot get ApplicationContext", e);}
You need to implement the org.quartz.Job interface and write the code that the task needs to perform in the public void execute (JobExecutionContext context) method.
ApplicationContext appContext = (ApplicationContext) context.getScheduler () .getContext () .get (Constants.APP_CONTEXT); you can get the ApplicationContext of Spring, and the objects managed by Spring can be obtained through ApplicationContext, such as Collector collector = appContext.getBean (Collector.class);. Note: this method must be used in this class to get Spring-managed objects, not in other ways such as @ Autowired.
Integer collectId = map.getIntegerFromString (COLLECT_ID); additional parameters can be obtained.
Additional parameters
ScheduleJobPath.com.jspxcms.core.quartz.InfoPublishJob= if no additional parameters are needed for a scheduled task, leave a blank after the equal sign.
Timing tasks sometimes need to pass non-parameters, such as collection timing tasks need to choose which collection data source to execute. At this point, you need to add corresponding entries in the scheduled task add / modify interface.
ScheduleJobPath.com.jspxcms.ext.quartz.CollectJob=/cmscp/ext/collect/schedule_job.do
Input Controller of the interface
Write an address to get the input interface: / cmscp/ext/collect/schedule_job.do, where the relative path is used to add the address of the interface relative to the scheduled task.
In this case, the implementation class for this address is com.jspxcms.ext.web.back.CollectController.
@ Controller@RequestMapping ("/ ext/collect") public class CollectController {. @ RequestMapping ("schedule_job.do") public String scheduleJob (HttpServletRequest request, org.springframework.ui.Model modelMap) {Integer siteId = Context.getCurrentSiteId (); List collectList = service.findList (siteId); modelMap.addAttribute ("collectList", collectList); modelMap.addAttribute ("includePage", ".. / ext/collect/collect_job.jsp") Return "core/schedule_job/schedule_job_form";}.}
ModelMap.addAttribute ("collectList", collectList); pass data.
ModelMap.addAttribute ("includePage", ".. /.. / ext/collect/collect_job.jsp"); transfer input interface.
Input JSP of the interface
According to the value of includePage passed in Controller, the corresponding JSP page is: / WEB-INF/views/ext/collect/collect_job.jsp.
: ${collect.name}
The data_collectId here corresponds to the method Integer collectId = map.getIntegerFromString ("collectId") for obtaining parameters in the timed task implementation class CollectJob
: ${collectList} here corresponds to CollectController's modelMap.addAttribute ("collectList", collectList);.
This is the end of the article on "how to develop timed tasks in jspXCMS". Thank you for reading! I believe that everyone has a certain understanding of the knowledge of "how to develop timed tasks in jspXCMS". If you want to learn more, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.