??xml version="1.0" encoding="utf-8" standalone="yes"?> 首先Q如果你?/span>web.xml文g中的配置是这LQ?/span> <context-param> 那么需要在工程下创Z个以applicationContext- 为开头的xml文geg:applicationContext-jobconfig.xml xml的头和结N分跟其他spring配置文g怼Q就不赘qͼ正文如下Q?/span> <bean id="youJobName(cd?/span>)" class="com.******.YourJobClassLocation(cȝ定位)" /> <bean id="doScheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> q样的配|几本就可以q{了,但是有一个地方可能是你需要根据你的需求来定的,那就是触发时间?/span> 下面有一些关于时间配|的说明Q?/span> 字段序 允许?/span> 允许的特D字W?/span> U?/span> 0-59 , - * / ?/span> 0-59 , - * / 时 0-23 , - * / 日期 1-31 , - * ? / L W C 月䆾 1-12 或?JAN-DEC , - * / 星期 1-7 或?SUN-SAT , - * ? / L C # q_可选) 留空, 1970-2099 , - * / "/"字符用来指定渐增的倹{例?/span>0/15出现在秒字段的时候意味着“在第0Q?/span>15Q?/span>30?/span>45U?/span>”Q的时候被触发Q。?/span>5/15出现在秒字段的时候意味着“在第5Q?/span>20Q?/span>35和第50U?/span>”Q的时候被触发Q?/span>"*/"?/span>"0/"的指定是{h的?/span> 注:当分?/span>+分母的值大于该字段的最大|如在U钟字段出现45/20的时候,表示在第45U以后的?/span>20会触发一ơ,但是20U以后又做另外的时间段以内了,所以该字段?/span>/20卛_效,如改?/span>45/10 则只?/span>W?/span>45 ?/span>55U会执行一ơ?/span> quartz的高U特性不仅如?/span>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/classes/applicationContext-*.xml
</param-value>
</context-param>
<bean id="doYourJob(别名)" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject">
<ref bean="youJobName(cd?/span>)""/>
</property>
<property name="targetMethod">
<value>runMethodName(定时执行的方法名)</value>
</property>
</bean>
<bean id="youJobNameTrigger(触发器别?/span>)" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail">
<ref bean="doYourJob(别名)""/>
</property>
<property name="cronExpression">
<value>0 0/20 * * * ?(定时的时间配|?/span>)</value>
</property>
</bean>
<property name="triggers">
<list>
<ref local="youJobNameTrigger(触发器别?/span>)"/>
</list>
</property>
</bean>
The '*' character is used to specify all values. For example, "*" in the minute field means "every minute".
“*”字符被用来指定所有的倹{如Q?/span>”*“在分钟的字段域里表示“每分?/span>”?/span>
The '?' character is allowed for the day-of-month and day-of-week fields. It is used to specify 'no specific value'. This is useful when you need to specify something in one of the two fileds, but not the other. See the examples below for clarification.
“?”字符只在日期域和星期域中使用。它被用来指?/span>“非明的?/span>”。当你需要通过在这两个域中的一个来指定一些东西的时候,它是有用的。看下面的例子你׃明白?/span>
月䆾中的日期和星期中的日期这两个元素时互斥的一起应该通过讄一个问?/span>(?)来表明不惌|那个字D?/span>
The '-' character is used to specify ranges For example "10-12" in the hour field means "the hours 10, 11 and 12".
“-”字符被用来指定一个范围。如Q?/span>“10-12”在小时域意味着“10炏V?/span>11炏V?/span>12?/span>”?/span>
The ',' character is used to specify additional values. For example "MON,WED,FRI" in the day-of-week field means "the days Monday, Wednesday, and Friday".
“,”字符被用来指定另外的倹{如Q?/span>“MON,WED,FRI”在星期域里表C?/span>”星期一、星期三、星期五”.
The '/' character is used to specify increments. For example "0/15" in the seconds field means "the seconds 0, 15, 30, and 45". And "5/15" in the seconds field means "the seconds 5, 20, 35, and 50". Specifying '*' before the '/' is equivalent to specifying 0 is the value to start with. Essentially, for each field in the expression, there is a set of numbers that can be turned on or off. For seconds and minutes, the numbers range from 0 to 59. For hours 0 to 23, for days of the month 0 to 31, and for months 1 to 12. The "/" character simply helps you turn on every "nth" value in the given set. Thus "7/6" in the month field only turns on month "7", it does NOT mean every 6th month, please note that subtlety.
The 'L' character is allowed for the day-of-month and day-of-week fields. This character is short-hand for "last", but it has different meaning in each of the two fields. For example, the value "L" in the day-of-month field means "the last day of the month" - day 31 for January, day 28 for February on non-leap years. If used in the day-of-week field by itself, it simply means "7" or "SAT". But if used in the day-of-week field after another value, it means "the last xxx day of the month" - for example "6L" means "the last friday of the month". When using the 'L' option, it is important not to specify lists, or ranges of values, as you'll get confusing results.
L?/span>‘last’的省略写法可以表C?/span>day-of-month?/span>day-of-week域,但在两个字段中的意思不同,例如day-of-month域中表示一个月的最后一天,
如果?/span>day-of-week域表C?/span>‘7’或?/span>‘SAT’Q如果在day-of-week域中前面加上数字Q它表示一个月的最后几天,例如‘6L’pCZ个月的最后一?/span>
星期五,
The 'W' character is allowed for the day-of-month field. This character is used to specify the weekday (Monday-Friday) nearest the given day. As an example, if you were to specify "15W" as the value for the day-of-month field, the meaning is: "the nearest weekday to the 15th of the month". So if the 15th is a Saturday, the trigger will fire on Friday the 14th. If the 15th is a Sunday, the trigger will fire on Monday the 16th. If the 15th is a Tuesday, then it will fire on Tuesday the 15th. However if you specify "1W" as the value for day-of-month, and the 1st is a Saturday, the trigger will fire on Monday the 3rd, as it will not 'jump' over the boundary of a month's days. The 'W' character can only be specified when the day-of-month is a single day, not a range or list of days
.
The 'L' and 'W' characters can also be combined for the day-of-month expression to yield 'LW', which translates to "last weekday of the month".
The '#' character is allowed for the day-of-week field. This character is used to specify "the nth" XXX day of the month. For example, the value of "6#3" in the day-of-week field means the third Friday of the month (day 6 = Friday and "#3" = the 3rd one in the month). Other examples: "2#1" = the first Monday of the month and "4#5" = the fifth Wednesday of the month. Note that if you specify "#5" and there is not 5 of the given day-of-week in the month, then no firing will occur that month.
The 'C' character is allowed for the day-of-month and day-of-week fields. This character is short-hand for "calendar". This means values are calculated against the associated calendar, if any. If no calendar is associated, then it is equivalent to having an all-inclusive calendar. A value of "5C" in the day-of-month field means "the first day included by the calendar on or after the 5th". A value of "1C" in the day-of-week field means "the first day included by the calendar on or after sunday".
关于cronExpression的介l?/span>:
字段允许?/span>允许的特D字W?/span>
U?/span> 0-59 , - * /
?/span> 0-59 , - * /
时 0-23 , - * /
日期 1-31 , - * ? / L W C
月䆾 1-12 或?/span> JAN-DEC , - * /
星期 1-7 或?/span> SUN-SAT , - * ? / L C #
q_可选)留空, 1970-2099 , - * /
表达式意?/span>
"0 0 12 * * ?" 每天中午12点触?/span>
"0 15 10 ? * *" 每天上午10:15触发
"0 15 10 * * ?" 每天上午10:15触发
"0 15 10 * * ? *" 每天上午10:15触发
"0 15 10 * * ? 2005" 2005q的每天上午10:15触发
"0 * 14 * * ?" 在每天下?/span>2点到下午2:59期间的每1分钟触发
"0 0/5 14 * * ?" 在每天下?/span>2点到下午2:55期间的每5分钟触发
"0 0/5 14,18 * * ?" 在每天下?/span>2点到2:55期间和下?/span>6点到6:55期间的每5分钟触发
"0 0-5 14 * * ?" 在每天下?/span>2点到下午2:05期间的每1分钟触发
"0 10,44 14 ? 3 WED" 每年三月的星期三的下?/span>2:10?/span>2:44触发
"0 15 10 ? * MON-FRI" 周一臛_五的上午10:15触发
"0 15 10 15 * ?" 每月15日上?/span>10:15触发
"0 15 10 L * ?" 每月最后一日的上午10:15触发
"0 15 10 ? * 6L" 每月的最后一个星期五上午10:15触发
"0 15 10 ? * 6L 2002-2005" 2002q至2005q的每月的最后一个星期五上午10:15触发
"0 15 10 ? * 6#3" 每月的第三个星期五上?/span>10:15触发
每天早上6?/span>
0 6 * * *
每两个小?/span>
0 */2 * * *
晚上11点到早上7点之间每两个时Q早上八?/span>
0 23-7/2Q?/span>8 * * *
每个月的4号和每个C拜的礼拜一到礼拜三的早?/span>11?/span>
0 11 4 * 1-3
1?/span>1日早?/span>4?/span>
0 4 1 1 *
1 数据库存?/span>
2 集群支持
3 数据库持久化dQ?/span>trigger
4 trigger 的停止,q行
5 d的Q意添?/span>
6 ?/span>corntrigger 更详的d安排
7 U程的内部数据交?/span>
]]>
Spring的事务管理是l常用到的,论坛里已l不知讨Z多少变了?
记录下几个讲的比较清楚的?/p>
spring事务探烦
http://www.javaeye.com/topic/11190
解惑 spring 嵌套事务
http://www.javaeye.com/topic/35907?page=1
Spring声明式事务管理源码解?
http://www.javaeye.com/topic/87426?page=1
详解spring事务属?
http://www.javaeye.com/post/282638
附:事务的概?/p>
一.原子性(AtomicQ?/span> ?一致性(ConsistentQ?/span> ?隔离性(IsolatedQ?/span> ?持久性(DurableQ?/span> ?/span>DynamicProxyDemo目的例子中Q记录的动作原先被横切(Cross-cuttingQ入?/span>HelloSpeaker本n所负责的业务流E之中,另外cM于记录这cȝ动作Q如安全Q?/span>SecurityQ检查、事务(TransactionQ等pȝ层面的服务(ServiceQ,在一些应用程序之中常被见到安插至各个对象的处理流E之中,q些动作?/span>AOP的术语中被称之ؓCross-cutting concerns?/span> 以图片说明可?/span>Cross-cutting concerns的意涵,例如原来的业务流E是很单U的Q?/span> 现在Z要加入记录(LoggingQ与安全Q?/span>SecurityQ检查等服务Q对象的E序代码中若被硬生生的写入相关的Logging?/span>SecurityE序片段Q则可用以下图解表C出Cross-cutting?/span>Cross-cutting concerns的概念: Cross-cutting concerns若直接撰写在负责某业务的对象之流E中Q会使得l护E序的成本增高,例如若您今天要将对象中的记录功能修改或是U除该服务,则必MҎ有撰写曾记录服务的程序代码,然后重新~译Q另一斚wQ?/span>Cross-cutting concernsh于业务逻辑之中Q得业务对象本w的逻辑或程序的撰写更ؓ复杂?/span> 散落于各个业务对象之中?/span>Cross-cutting concerns攉hQ设计各个独立可重用的对象,q些对象UC?/span>AspectQ例如在DynamicProxyDemo目中将d的动作设计ؓ一?/span>LogHandlercdQ?/span>LogHandlercd?/span>AOP的术语就?/span>Aspect的一个具体实例,?/span>AOP中着重于Aspect的L认,之从业务流E中独立出来Q在需要该服务的时候,~合Q?/strong>WeaveQ?/span>臛_用程序之上,不需要服务的时候,也可以马上从应用E序中脱,应用E序中的可重用组件不用作M的修改,例如?/span>DynamicProxyDemo目中的HelloSpeaker所代表的角色就是应用程序中可重用的lgQ在它需要记录服务时q不用修Ҏw的E序代码?/span> 另一斚wQ对于应用程序中可重用的lg来说Q以AOP的设计方式,它不用知道处理提供服务的对象之存在,具体的说Q与服务相关?/span>API不会出现在可重用的应用程序组件之中,因而可提高q些lg的重用性,您可以将q些lg应用臛_它的应用E序之中Q而不会因为目前加入了某些服务而与目前的应用程序框架发生耦合?/span> Aspect的具体实作称之ؓAdviceQ以记录的动作而言Q?/span>Advice中会包括真正的记录程序代码是如何实作的,像是DynamicProxyDemo目中的LogHandlercd是Advice的一个具体实例,Advice中包括了Cross-cutting concerns的行为或所要提供的服务?/span> Aspect在应用程序执行时加入业务程的点或时机称之ؓJoinpointQ具体来_是Advice在应用程序中被呼叫执行的时机Q这个时机可能是某个Ҏ被呼叫之前或之后Q或两者都有)Q或是某个例外发生的时候?/span> Pointcut是一个定义,藉由q个定义您可以指定某?/span>Aspect在哪?/span>Joinpoint时被应用臛_用程序之上。具体的_您可以在某个定义档中撰写PointcutQ当中说明了哪些Aspect要应用至应用E序中的哪些Joinpoint?/span> 一?/span>Advice被应用的对象或目标对象,例如DynamicProxyDemo目中的HelloSpeaker是LogHandlerq个Advice?/span>Target?/span> 对于一个现存的cdQ?/span>Introduction可以为其增加行ؓQ而不用修改该cd的程序,具体的说Q您可以为某个已撰写、编译完成的cdQ在执行时期动态加入一些方法或行ؓQ而不用修Ҏ新增M一行程序代码?/span> ?strong>?/strong>Expert One-on-One J2EE Development WIthout EJB?/span>一书中Q?/span>Rod Johnson?/span>Juergen Hoeller在第八章中有提到Q?/span>AOP的实作有五个主要的策略:Dynamic Proxies?/span>Dynamic Byte Code Generation?/span>Java Code Generation?/span>Use of a Custon Class Loader?/span>Language Extensions?/span> 在之前静态代理与动态代理中Q已l用实际的E序范例介绍q代理机制的实现Q?/span>Spring?/span>AOP主要是透过动态代理来完成?/span> Advice被应用至对象之上的过E称之ؓ~合Q?/span>WeaveQ,?/span>AOP中缝合的方式有几个时间点Q编译时期(Compile timeQ、类别加载时期(Classload timeQ、执行时期(RuntimeQ?/span> l合DynamicProxyDemo的实例,以上介l过?/span>AOP相关名词具体的用图片来加以表示Q有助于您对每一个名词的理解与认识: 2、我们需要对该接口进行实现的Ҏ:OrderManagerImpl.java 3、spring配置发送email的applicationContext-email.xml 4、最后配|自qjsp面以及action 到此所有的开发以l束?br />
Sring邮g抽象层的主要包是Qorg.springframework.mail 包。它包含叫MailSender为发送邮件的核心接口和包含简单邮件属性例如from,to,cc,subject,text叫SimpleMailMessage的值对? q个包也包含一个检查异常的层次Q它支持一个更高别的抽象过低别的邮gpȝ异常伴随根异常存在MailException. 请参考JavaDocs为更多的信息杂邮件异常层ơ?/p>
spring in action in action also provides a sub-interface of MailSender for specialized JavaMail features such as MIME messages, namely org.springframework.mail.javamail.JavaMailSender It also provides a callback interface for preparation of JavaMail MIME messages, namely org.springframework.mail.javamail.MimeMessagePreparator Spring也支持一个MailSender的专用于JavaMail特征例如MIME消息子接口,命名为org.springframework.javamail.JavaMailerSener。它也支持一个ؓJavaMail MIME信息的准备回调接口,命名为org.springframework.mail.JavaMail.MimeMessagePreparator.
事务׃个或多个行ؓl成QŞ成一个工作单元。原子性确保在q个工作单元中的所有操作要么都发生Q要么都不发生。Q何一个行为失败,整个事务回滚?/p>
一旦一个事务结束了Q不成功与否,pȝ所处状态和它的也ؓ规则是一致的Q就数据应当不会被破坏?/p>
事务应该允许多个用户操作同一个数据,但用户之间不会互相媄响。因此,事务必须是隔ȝQ防止ƈ发读写同一个数据的情况发生?/p>
一旦事务成功完成,事务的结果就应该被持久化下来?
]]>
]]>
2 /**
3 *email,要发送的邮g地址;
4 *Code:Ȁzȝ
5 */
6 public void placeOrder(String email);
7 }
2 import javax.mail.MessagingException;
3 import javax.mail.internet.InternetAddress;
4 import javax.mail.internet.MimeMessage;
5 import org.springframework.mail.MailException;
6 import org.springframework.mail.javamail.JavaMailSender;
7 import org.springframework.mail.javamail.MimeMessagePreparator;
8 import service.OrderManager;
9
11 public class OrderManagerImpl extends BaseManagerImpl implements OrderManager {
12
13 private JavaMailSender mailsender;
14 private MyMailMessage message;
15
16
17 public void setMessage(CityMailMessage message)
18 {
19 this.message = message;
20 }
21 public void setMailsender(JavaMailSender mailsender) {
22 this.mailsender = mailsender;
23 }
24 public void placeOrder(final String email) {
25
26
27 MimeMessagePreparator preparator = new MimeMessagePreparator() {
28 public void prepare(MimeMessage mimeMessage) throws MessagingException {
29 mimeMessage.setRecipient(Message.RecipientType.TO,
30 new InternetAddress(email));
31 mimeMessage.setFrom(new InternetAddress(message.getFrom()));
32 /**转换~码为GBK*/
33 mimeMessage.setSubject(message.getSubject(),"GBK");
36 mimeMessage.setText(email+"<br>"+message.getSubject()+message.getText(),"GBK");
37
38 }
39 };
40 try{
41 mailsender.send(preparator);
42 }
43 catch(MailException ex) {
44 //log it and go on
45 System.err.println(ex.getMessage());
46 }
47 }
48 }
2 <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
3 "http://www.springframework.org/dtd/spring-beans.dtd">
4
5 <beans>
6 <bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
7 <property name="host">
8 <value>smtp.163.com</value>
9 </property>
10 <property name="username">
11 <value>username</value>
12 </property>
13 <property name="password">
14 <value>password</value>
15 </property>
16 <property name="javaMailProperties">
17 <props>
18 <prop key="mail.smtp.auth">true</prop>
19 <prop key="mail.smtp.timeout">25000</prop>
20 </props>
21 </property>
22 </bean>
23
24 <bean id="mailMessage" class="org.springframework.mail.SimpleMailMessage">
25 <property name="from">
26 <value>Email</value>
27 </property>
28 <property name="subject">
29 <value>标题</value>
30 </property>
31 <property name="text">
32 <value>内容</value>
33 </property>
46 </bean>
47
48 <bean id="orderManager" class="cn.cityyouth.service.impl.OrderManagerImpl">
49 <property name="mailsender">
50 <ref bean="mailSender" />
51 </property>
52 <property name="message">
53 <ref bean="mailMessage" />
54 </property>
55 </bean>
56
57 </beans>
2
3 import javax.servlet.http.HttpServletRequest;
4 import javax.servlet.http.HttpServletResponse;
5 import org.apache.struts.action.ActionForm;
6 import org.apache.struts.action.ActionForward;
7 import org.apache.struts.action.ActionMapping;
8 import org.apache.struts.action.ActionMessage;
9 import org.apache.struts.action.ActionMessages;
10 import com.test.service.OrderManager;
11
12 public class SendMailAction extends BaseAction {
13
14 /**
15 * Method execute
16 *
17 * @param mapping
18 * @param form
19 * @param request
20 * @param response
21 * @return ActionForward
22 */
23 public ActionForward execute(ActionMapping mapping, ActionForm form,
24 HttpServletRequest request, HttpServletResponse response) {
25 OrderManager omi=(OrderManager)this.getBean("orderManager");
26 String useremail="123@163.com";
27 omi.placeOrder(useremail);
28 }
29 }
]]>
]]>
]]>