fei.wang
2024-03-07 80c20bb65f4b73d8beb817e0d595889cd44479dd
1
2
3
4
5
6
7
8
9
10
11
12
13
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:aop="http://www.springframework.org/schema/aop" xmlns:task="http://www.springframework.org/schema/task"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd
 
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context.xsd
 
       http://www.springframework.org/schema/mvc
       http://www.springframework.org/schema/mvc/spring-mvc.xsd
 
       http://www.springframework.org/schema/aop
       http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd">
 
    <!--<bean id="helloController" class="com.example.controller.HelloController"></bean>-->
    <!--开启这个配置,spring才能识别@Scheduled注解 -->
    <task:annotation-driven scheduler="qbScheduler" mode="proxy"/>
    <task:scheduler id="qbScheduler" pool-size="10"/>
    <!--开放注解功能-->
    <context:annotation-config/>
    <!--指定扫描和解析哪些包下面的类-->
    <context:component-scan base-package="com.flow"/>
 
    <!--开启mvc相关注解-->
    <mvc:annotation-driven/>
 
    <!--放行静态资源的-->
    <mvc:resources mapping="/css/**" location="/css/"/>
    <mvc:resources mapping="/js/**" location="/js/"/>
    <mvc:resources mapping="/font/**" location="/font/"/>
    <mvc:resources mapping="/images/**" location="/images/"/>
    <mvc:resources mapping="/api/**" location="/api/"/>
    <mvc:resources mapping="/page/**" location="/page/"/>
    <!--配置数据源-->
    <bean id="ds" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
        <property name="url" value="jdbc:mysql:///hxzkflow?characterEncoding=UTF8"/>
        <property name="username" value="root"/>
        <property name="password" value="123456"/>
    </bean>
 
    <!--配置Mybatis的SqlSessionFactoryBean-->
    <bean id="sqlSessionFactory" class="com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean">
        <property name="dataSource" ref="ds"/>
        <!--分页-拦截器-->
        <property name="plugins">
            <array>
                <bean class="com.github.pagehelper.PageInterceptor">
                    <property name="properties">
                        <!--使用下面的方式配置参数,一行配置一个(键=值)-->
                        <value>
                            helperDialect=mysql
                        </value>
                    </property>
                </bean>
            </array>
        </property>
    </bean>
    <!-- 配置MapperScan:用来扫描用户自定义的mapper接口 -->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.flow.mapper"/>
    </bean>
 
 
 
    <!-- 定义一个任务类 -->
    <bean id="MyJob" class="com.flow.quartz.MyJob"></bean>
    <bean id="MyJob2" class="com.flow.quartz.MyJob2"></bean>
    <bean id="MyJob3" class="com.flow.quartz.MyJob3"></bean>
    <!-- jobDetail -->
    <bean id="jobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
        <!--ref中是自定义的类-->
        <property name="targetObject" ref="MyJob"></property>
        <!--value是自定义类MyJob中的方法名-->
        <property name="targetMethod" value="execute"></property>
        <property name="concurrent" value="false" /><!-- 作业不并发调度  -->
    </bean>
 
    <!-- jobDetail2 -->
    <bean id="jobDetail2" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
        <!--ref中是自定义的类-->
        <property name="targetObject" ref="MyJob2"></property>
        <!--value是自定义类MyJob2中的方法名-->
        <property name="targetMethod" value="execute1"></property>
        <property name="concurrent" value="false" /><!-- 作业不并发调度  -->
    </bean>
    <!-- jobDetail3 -->
    <bean id="jobDetail3" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
        <!--ref中是自定义的类-->
        <property name="targetObject" ref="MyJob3"></property>
        <!--value是自定义类MyJob2中的方法名-->
        <property name="targetMethod" value="execute1"></property>
        <property name="concurrent" value="false" /><!-- 作业不并发调度  -->
    </bean>
 
    <!-- 定义trigger 触发器 -->
    <bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
        <property name="jobDetail" ref="jobDetail"></property>
        <property name="cronExpression" value="0 0 0 * * ?"></property>
    </bean>
 
    <!-- 定义第二个trigger 触发器 -->
    <bean id="cronTrigger2" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
        <property name="jobDetail" ref="jobDetail2"></property>
        <property name="cronExpression" value="0 0 12 */2 * ?"></property>
    </bean>
    <!-- 定义第三个个trigger 触发器 -->
    <bean id="cronTrigger3" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
        <property name="jobDetail" ref="jobDetail3"></property>
        <property name="cronExpression" value="0 0 12 */2 * ?"></property>
    </bean>
 
    <bean id="scheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
        <property name="configLocation" value="classpath:quartz.properties" />
        <property name="overwriteExistingJobs" value="true" />
        <property name="autoStartup" value="true" />
        <property name="triggers">
            <list>
                <ref bean="cronTrigger"/>
                <ref bean="cronTrigger2"/>
                <ref bean="cronTrigger3"/>
            </list>
        </property>
    </bean>
</beans>