Spring Boot integrated Persistence quartz timed task management and interface display

Source: Internet
Author: User
Tags thread class
Preface

This article is a revision and supplement to the previous article Spring+springmvc+mybatis+quartz the Integration Code section, the biggest change is that the background frame becomes spring Boot.

The technology or tools used in this project are: Spring Boot Mybatis Quartz pagehelper vuejs elementui mysql database body configuration

In this case, we still use the MySQL database as the storage carrier for quartz task persistence. There is a detailed introduction to how to set up tables in the MySQL database in the previous Spring+springmvc+mybatis+quartz integration. Here we look at how the Spring boot project is built. On the spring website there are scaffolding for building the Spring Boot project, which we set as shown below and then click Generate Project.


Then we import this MAVEN project in the IDE, and then we can see that there is a file named Application.properties under Src/main/resource, the contents of which are empty. We delete this file and then create a new file named Application.yml in this directory. This is another way to configure the Spring boot project and is also a configuration that is officially recommended by spring boot. In this new yml file, we add the following code

Spring:
  DataSource:
    url:jdbc:mysql://190.0.1.88:3306/hello_test?useunicode=true
    username:root
    Password:root
    driver-class-name:com.mysql.jdbc.driver

mybatis: 
  mapper-locations:
  -classpath: Com/example/demo/mapper/*.xml
  type-aliases-package:com.example.demo.entity
   
   
    
    1
    
    2
    
    3
    
    4
    
    5
    
    6
    
    7
    
    8
    
    9
    
    11
   
   

The above code is some configuration of the database and MyBatis.

Next we create a new file named Quartz.properties in the current directory. This is the configuration file for Quartz. Add the following code:

# fixed prefix Org.quartz # mainly divided into scheduler, ThreadPool, Jobstore, plugin and other parts # # org.quartz.scheduler.instanceName =
Defaultquartzscheduler Org.quartz.scheduler.rmi.export = False Org.quartz.scheduler.rmi.proxy = False
Org.quartz.scheduler.wrapJobExecutionInUserTransaction = False # When instantiating ThreadPool, the thread class used is Simplethreadpool Org.quartz.threadPool.class = Org.quartz.simpl.SimpleThreadPool #
ThreadCount and ThreadPriority will inject ThreadPool instances in the form of setter # number of concurrent Org.quartz.threadPool.threadCount = 5 # Priority
Org.quartz.threadPool.threadPriority = 5

Org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread = True Org.quartz.jobStore.misfireThreshold = 5000 # default is stored in memory #org. Quartz.jobStore.class = Org.quartz.simpl.RAMJobStore #持久化 o

Rg.quartz.jobStore.class = Org.quartz.impl.jdbcjobstore.JobStoreTX Org.quartz.jobStore.tablePrefix = qrtz_

Org.quartz.jobStore.dataSource = Qzds Org.quartz.dataSource.qzDS.driver = Com.mysql.jdbc.Driver Org.quartz.dataSource.qzDS.URL = Jdbc:mysql://190.0.1.88:3306/hello_Test?useunicode=true&characterencoding=utf-8 Org.quartz.dataSource.qzDS.user = root
    
    Org.quartz.dataSource.qzDS.password = Root Org.quartz.dataSource.qzDS.maxConnections = 10 1 2 3 4 5 6 7 8 9 10 11 12 1
    
    3 14 15 16 17 18 19 20 21 22 23
    
    24 25 26 27 28 29 30 31 32 33
   
    34 35 36 37 38 39 40

The

can be seen in the same configuration file as the previous article. Then we create a new file named Schedulerconfig.java under the Com.example.demo. In this file, we read the new quartz.properties file that we just created.

Package Com.example.demo;
Import java.io.IOException;

Import java.util.Properties;

Import Javax.sql.DataSource;
Import Org.quartz.ee.servlet.QuartzInitializerListener;
Import Org.springframework.beans.factory.config.PropertiesFactoryBean;
Import Org.springframework.context.annotation.Bean;
Import org.springframework.context.annotation.Configuration;
Import Org.springframework.core.io.ClassPathResource;

Import Org.springframework.scheduling.quartz.SchedulerFactoryBean; @Configuration public class Schedulerconfig {@Bean public schedulerfactorybean Schedulerfactorybean (DataSource D
        Atasource) throws IOException {Schedulerfactorybean factory = new Schedulerfactorybean ();
        Factory.setquartzproperties (Quartzproperties ());
    return factory; } @Bean Public Properties quartzproperties () throws IOException {Propertiesfactorybean propertiesfactory
        Bean = new Propertiesfactorybean (); Propertiesfactorybean.setlocation (New ClasspathresoUrce ("/quartz.properties"));
    return Propertiesfactorybean.getobject ();
    } @Bean Public Quartzinitializerlistener Executorlistener () {return new Quartzinitializerlistener ();
    
    }} 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 2
    
    0 21 22 23 24 25 26 27 28 29 30
   
    31 32 33 34 35 36 37 38

Note the quartzinitializerlistener at the bottom. In Springmvc, when we configure quartz, we add the following configuration to the Web. xml:

    <listener>
        <listener-class>
            org.quartz.ee.servlet.QuartzInitializerListener
        </ Listener-class>
    </listener>
   
   
    
    

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.