استخدم الربيع لدمج الكوارتز لتنفيذ المؤقت (مشروع Maven للتظاهر)
الطرق التي لا تستند إلى فئات قاعدة محددة
1. بيئة التنمية وحزم جرة التبعية
الربيع 4.2.6.release
مافن 3.3.9
JDK 1.7
فكرة 15.04
2. تبعية جرة لا غنى عنها (تمت إضافتها في ملف pom.xml في مشروع Maven)
<Rependency> <roupeD> org.springframework </rougiD> <StifactId> spring-context-support </artifactId> <الإصدار> 4.2.6. </التبعية>
3. الملفات المستخدمة عند تنفيذ المؤقت:
Planworkexcute.java - فئة تنفذها المؤقت
spring-plan.xml-xml لتكوين معلومات المؤقت
رابعًا ، قم بتنفيذ خطوات المؤقت:
1. إنشاء ملف planworkexcute.java ، تحت حزمة cc.royo.plantask.
package cc.royao.plantask ؛ استيراد java.text.simpleDateFormat ؛ استيراد java.util.date ؛ استيراد java.util.hashmap ؛ استيراد java.util.list ؛ import java.util.map ؛ استيراد java.util.concurrent.executorservic org.apache.log4j.logger ؛ // يمكنك حذف استيراد org.springframework.beans.factory.annotation.autowired ؛ plantkexecute الطبقة العامة planworkexecute سحبت aughoAudittask () {simpledateformat outformat = new SimplEdateFormat ("Yyyyy MM Month DDD HH: MM: SS") ؛ System.out.println("Start withdrawal exemption task------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- logger.info ("ابدأ الانسحاب والإعفاء من المراجعة مهمة---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------2. إنشاء ملف تكوين spring-plan.xml ملاحظة: فقط قم بإنشاء ملف تكوين مؤقت. إذا كانت هناك حاجة إلى أجهزة ضبط الوقت المتعددة ، فما عليك سوى إضافة الفاصوليا في spring-lan.xml وتحديد طريقة فئة المؤقت. ليست هناك حاجة لإنشاء XML متعددة.
・ للتعبير cron عن المدة التي سيتم تنفيذ الموقت ، يرجى الرجوع إلى: http://www.vevb.com/article/138900.htm
・ عنوان URL لإنشاء التعبيرات عبر الإنترنت: http://cron.qqe2.com/
<؟ xmlns = "http://www.springframework.org/schema/beans" xmlns: xsi = "http://www.w3 http://www.springframework.org/schema/beans/spring-beans-2.5. <ref bean = "job1"/> </property> <property name = "targetmethod"> <value> سحبت audittask </value> <!-اسم طريقة فئة الموقت-> </property> </bean> <bean id = "crontrigger_1"> property name = "jobdetail"> name = "cronexpression"> <value> 0/2 * * * *؟ </value> <!- 0 10 0 * *؟ قم بتنفيذ على 0:10 كل يوم-> </property> </bean> <bean> <property name = "triggers"> <list> <re ref local = "crontrigger_1"/> <!-تمت إضافة كل مؤقت ، يجب عليك أيضًا إضافة-> </list> </property>
3. تحتاج إلى تقديم spring-plan.xml في ApplicationContext.xml. يركز الرمز التالي على النتيجة النهائية
<؟ xmlns: jee = "http://www.springframework.org/schema/jee" xmlns: aop = "http://www.springframework.org/schema/aop" xmlns: mvc = "http://www.springframework.org/schema/mvc" Xmlns: Cache = "http://www.springframework.org/schema/cache" http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/spring-tx-3 http://www.springframework.org/schema/context http://www.springframework.org/schema/aop/spring-aop-3.1.XSD http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-3.xsd التكوين-> <bean id = "propertyConfigurer"> <property name = "sortes"> <list> <value> web-inf/jdbc.properties </value> <!-<value> web-inf/sms.properties </value>-> </list> </spertar <Value> $ {jdbc.driverclass} </value> </sprention> <!-<property name = "defaultautocommit" value = "false"/>-> <property name = "url" name = "username"> <value> $ {jdbc.username} </value> </sopperation> <property name = "password"> <value> $ {jdbc.password} </value> </surement> <samperation> </value> </value> </value> </value> </value> <value> 20000 </value> <!-0-> </property> <property name = "removaBandOned"> <value> true </value> </property> <property name = "removaBandOnedTimeout"> <value> 60000000 </value> <!-180-> </propert name = "testwhileIdle" value = "true"> </property> <property name = "testOnBorrow" value = "true"> </property> <property name = "testOnBorrow" value = "true" name = "minevictableDletImemillis" value = "120000"> </property> <!-إضافة-> </bean> <!-sqlsessionfactory-> <bean id = "sqlsessionfactory"> <property name = "dataSource" ref = "datasource"/> </bean id = value = "1"/> <property name = "maxpoolsize" value = "10"/> <property name = "keepaliveseconds" value = "300"/> <property name = "queUeCapacity" value = "50"/> <property name = "QuiptORCESTOC MOPLETEDONDDOWN" ref = "datasource"> </property> </bean> <!-<!-<!-<context: component-scan base-package = "com.royao">-> <!-<contex proxy-target-class = "true"> <aop: pointcut id = "serviceOperation" expression = "execution (*cc.royao.mana.auth.service.*. <tx: ide id = "txAdvice" TransAction-manager = "TransactionManager"> <tx: entributes> <tx: method name = "*" Rollback-for = "insistract"/> </tx: attributes> </sx: expration> <tx: exploy id = name = "*insert*" spection = "requiret"/> <tx: method name = "*add*" spection = "required"/> <tx: method name = "*update*" spection = "required"/> <tx: method name = "update* <tx: method name = "batchdelfm" spection = "requiret"/> <tx: method name = "edittemplate" spection = "required"/> <tx: method name = "dummydelete" spection = "required"/> <tx: method name = "batchdeluser </tx: السمات> </tx: نصيحة> <bean> <property name = "basePackage"> <value> cc.royao.mana.auth.mapper.*</value> </pregerty> <property name = "sqlSessionFactoryBeannam هنا ، قمت بنسخ محتوى ملف XML بالكامل ، أخشى أنك لا تعرف مكان إدراجها-> <import Resource = "Spring-plan.xml"/> </bons>لخص
ما سبق هو ما قدمه المحرر لك باستخدام الربيع المدمج الكوارتز لتنفيذ وظيفة المؤقت. آمل أن يكون ذلك مفيدًا للجميع. إذا كان لديك أي أسئلة ، فيرجى ترك رسالة لي وسوف يرد المحرر على الجميع في الوقت المناسب. شكرا جزيلا لدعمكم لموقع wulin.com!