1. Download xxl-job-admin source code
Download address: https://github.com/xuxueli/xxl-job/releases document address: https://www.xuxueli.com/xxl-job/ I download version to 2.3.0Copy the code
2. Run the database script
The script is stored in xxl-job-2.3.0\doc\db\tables_xxl_job.sqlCopy the code
3. Modify the configuration file
Config file path: xxl-job-2.3.0\xxl-job-admin\ SRC \main\resources\application.properties Modify database configuration and mailbox configuration as follows:Copy the code
4. Start the xxl-job-admin project
Start the class path: XXL - job - 2.3.0 \ XXL - job - admin \ SRC \ main \ Java \ com \ XXL \ job \ admin \ XxlJobAdminApplication JavaCopy the code
5. Check the browser
Address: 123456 http://localhost:8080/xxl-job-admin user name admin passwordCopy the code
6. Import maven configuration
Add maven configuration to another SpringBoot applicationCopy the code
<dependency>
<groupId>com.xuxueli</groupId>
<artifactId>xxl-job-core</artifactId>
<version>2.3.0</version>
</dependency>
Copy the code
7. Modify the configuration file
application.yml
Copy the code
8. Write the configuration class XxlJobConfig
import com.xxl.job.core.executor.impl.XxlJobSpringExecutor; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; /** * xxl-job config * * @author xuxueli 2017-04-28 */ @Configuration public class XxlJobConfig { private Logger logger = LoggerFactory.getLogger(XxlJobConfig.class); @Value("${xxl.job.admin.addresses}") private String adminAddresses; @Value("${xxl.job.executor.appname}") private String appName; @Value("${xxl.job.executor.ip}") private String ip; @Value("${xxl.job.executor.port}") private int port; @Value("${xxl.job.accessToken}") private String accessToken; @Value("${xxl.job.executor.logpath}") private String logPath; @Value("${xxl.job.executor.logretentiondays}") private int logRetentionDays; @Bean(initMethod = "start", destroyMethod = "destroy") public XxlJobSpringExecutor xxlJobExecutor() { logger.info(">>>>>>>>>>> xxl-job config init."); XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor(); xxlJobSpringExecutor.setAdminAddresses(adminAddresses); xxlJobSpringExecutor.setAppname(appName); xxlJobSpringExecutor.setIp(ip); xxlJobSpringExecutor.setPort(port); xxlJobSpringExecutor.setAccessToken(accessToken); xxlJobSpringExecutor.setLogPath(logPath); xxlJobSpringExecutor.setLogRetentionDays(logRetentionDays); return xxlJobSpringExecutor; }}Copy the code
9. Write test task classes
import com.xxl.job.core.handler.IJobHandler; import com.xxl.job.core.handler.annotation.XxlJob; import org.springframework.stereotype.Component; @Component public class SampleXxlJobHandler extends IJobHandler { @Override @XxlJob(value = "sampleXxlJobHandler") Public void execute() throws Exception {system.out.println (" automatic task "+ this.getClass().getSimplename () +" execute "); }}Copy the code
10. Add an actuator
On the executive management page, click the "Add" button to pop up the "add" box. Enter AppName (the same as the AppName configured in Point 7), name, automatic registration by default, and click Save.Copy the code
11. Add automatic tasks
On the task management page, select the actuator created in the previous step and click Add. The dialog box for adding an actuator is displayed. Enter the task description, manager, cron expression (there are buttons on the right of the input box to help generate cron expressions automatically), jobHandler (need to match the value in the XxlJob annotation in Step 9), and click Save.Copy the code
12. Perform automatic tasks
Start the Springboot service for configuring automatic tasks. On the task management page, select the automatic task to be executed and select Run once to view the result. In normal development, click Start to keep the task running. You can search for logs on the scheduling log page.Copy the code