??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲va欧美va在线观看,国产在线一区不卡,国产一区精品在线http://www.aygfsteel.com/Crying/category/25485.html????????, ??????????握! zh-cnSun, 16 Mar 2008 13:43:51 GMTSun, 16 Mar 2008 13:43:51 GMT60如何在Spring中配|定时Q?http://www.aygfsteel.com/Crying/articles/186638.htmlCryingCryingSun, 16 Mar 2008 10:31:00 GMThttp://www.aygfsteel.com/Crying/articles/186638.htmlhttp://www.aygfsteel.com/Crying/comments/186638.htmlhttp://www.aygfsteel.com/Crying/articles/186638.html#Feedback0http://www.aygfsteel.com/Crying/comments/commentRss/186638.htmlhttp://www.aygfsteel.com/Crying/services/trackbacks/186638.htmlhttp://www.aygfsteel.com/amigoxie/archive/2008/02/29/183046.html


首先Q如果你?/span>web.xml文g中的配置是这LQ?/span>

  <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
         /WEB-INF/classes/applicationContext-*.xml
        </param-value>
 </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="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>

 <bean id="doScheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
   <property name="triggers">
     <list>
      <ref local="youJobNameTrigger(
触发器别?/span>)"/>  
     </list>
   </property>
 </bean>

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

, - * /


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.

"/"字符用来指定渐增的倹{例?/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>

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" 2005
q的每天上午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" 2002
q至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/2
Q?/span>8 * * *
每个月的4号和每个C拜的礼拜一到礼拜三的早?/span>11?/span>
0 11 4 * 1-3
1?/span>1日早?/span>4?/span>
0 4 1 1 *

quartz的高U特性不仅如?/span>
1
数据库存?/span>
2
集群支持
3
数据库持久化dQ?/span>trigger
4 trigger
的停止,q行
5
d的Q意添?/span>
6
?/span>corntrigger 更详的d安排
7
U程的内部数据交?/span>



Crying 2008-03-16 18:31 发表评论
]]>
Spring的事务管?http://www.aygfsteel.com/Crying/articles/158555.htmlCryingCryingTue, 06 Nov 2007 06:56:00 GMThttp://www.aygfsteel.com/Crying/articles/158555.htmlhttp://www.aygfsteel.com/Crying/comments/158555.htmlhttp://www.aygfsteel.com/Crying/articles/158555.html#Feedback0http://www.aygfsteel.com/Crying/comments/commentRss/158555.htmlhttp://www.aygfsteel.com/Crying/services/trackbacks/158555.html转脓?地址忘记?对不起啊Q?br />

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>
事务׃个或多个行ؓl成QŞ成一个工作单元。原子性确保在q个工作单元中的所有操作要么都发生Q要么都不发生。Q何一个行为失败,整个事务回滚?/p>

?一致性(ConsistentQ?/span>
一旦一个事务结束了Q不成功与否,pȝ所处状态和它的也ؓ规则是一致的Q就数据应当不会被破坏?/p>

?隔离性(IsolatedQ?/span>
事务应该允许多个用户操作同一个数据,但用户之间不会互相媄响。因此,事务必须是隔ȝQ防止ƈ发读写同一个数据的情况发生?/p>

?持久性(DurableQ?/span>
一旦事务成功完成,事务的结果就应该被持久化下来?



Crying 2007-11-06 14:56 发表评论
]]>
AOP观念Q{载)http://www.aygfsteel.com/Crying/articles/144951.htmlCryingCryingThu, 13 Sep 2007 11:33:00 GMThttp://www.aygfsteel.com/Crying/articles/144951.htmlhttp://www.aygfsteel.com/Crying/comments/144951.htmlhttp://www.aygfsteel.com/Crying/articles/144951.html#Feedback2http://www.aygfsteel.com/Crying/comments/commentRss/144951.htmlhttp://www.aygfsteel.com/Crying/services/trackbacks/144951.htmlAOP全名?/span>Aspect-Oriented ProgrammingQ有关于AOP的许多名词术语都q于抽象Q单从字面上q不Ҏ理解其名词意义,q边以之前介绍代理机制的范例来逐一对照以介l?/span>AOP的术语与观念Q?/span>

  • <!--[if !supportLists]-->Cross-cutting concern

?/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>

  •   <!--[endif]-->Aspect

散落于各个业务对象之中?/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>

  • <!--[if !supportLists]-->Advice

Aspect的具体实作称之ؓAdviceQ以记录的动作而言Q?/span>Advice中会包括真正的记录程序代码是如何实作的,像是DynamicProxyDemo目中的LogHandlercd是Advice的一个具体实例,Advice中包括了Cross-cutting concerns的行为或所要提供的服务?/span> 

  • <!--[if !supportLists]-->Joinpoint

Aspect在应用程序执行时加入业务程的点或时机称之ؓJoinpointQ具体来_是Advice在应用程序中被呼叫执行的时机Q这个时机可能是某个Ҏ被呼叫之前或之后Q或两者都有)Q或是某个例外发生的时候?/span>

  • <!--[if !supportLists]--><!--[endif]-->Pointcut

Pointcut是一个定义,藉由q个定义您可以指定某?/span>Aspect在哪?/span>Joinpoint时被应用臛_用程序之上。具体的_您可以在某个定义档中撰写PointcutQ当中说明了哪些Aspect要应用至应用E序中的哪些Joinpoint?/span> 

  • <!--[if !supportLists]-->Target

一?/span>Advice被应用的对象或目标对象,例如DynamicProxyDemo目中的HelloSpeakerLogHandlerq个Advice?/span>Target?/span>

  • <!--[if !supportLists]--><!--[endif]-->Introduction

对于一个现存的cdQ?/span>Introduction可以为其增加行ؓQ而不用修改该cd的程序,具体的说Q您可以为某个已撰写、编译完成的cdQ在执行时期动态加入一些方法或行ؓQ而不用修Ҏ新增M一行程序代码?/span>

  • <!--[if !supportLists]--><!--[endif]-->Proxy

?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>

  • <!--[if !supportLists]-->Weave

Advice被应用至对象之上的过E称之ؓ~合Q?/span>WeaveQ,?/span>AOP中缝合的方式有几个时间点Q编译时期(Compile timeQ、类别加载时期(Classload timeQ、执行时期(RuntimeQ?/span>
 

l合DynamicProxyDemo的实例,以上介l过?/span>AOP相关名词具体的用图片来加以表示Q有助于您对每一个名词的理解与认识:



Crying 2007-09-13 19:33 发表评论
]]>
使用Spring邮g抽象层发送简单邮?转http://www.aygfsteel.com/shmily432685/archive/2005/12/30/26041.html)http://www.aygfsteel.com/Crying/articles/142701.htmlCryingCryingTue, 04 Sep 2007 09:35:00 GMThttp://www.aygfsteel.com/Crying/articles/142701.htmlhttp://www.aygfsteel.com/Crying/comments/142701.htmlhttp://www.aygfsteel.com/Crying/articles/142701.html#Feedback1http://www.aygfsteel.com/Crying/comments/commentRss/142701.htmlhttp://www.aygfsteel.com/Crying/services/trackbacks/142701.html 1、我们定义一个发送邮件的接口:OrderManager.java
1 public interface OrderManager extends BaseManager{
2 /**
3 *email,要发送的邮g地址;
4 *Code:Ȁzȝ
5 */
6      public void placeOrder(String email);
7 }

2、我们需要对该接口进行实现的Ҏ:OrderManagerImpl.java

 1 import javax.mail.Message;
 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 }

3、spring配置发送email的applicationContext-email.xml

 1 <?xml version="1.0" encoding="UTF-8"?>
 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>

4、最后配|自qjsp面以及action

 1 package cn.cityyouth.web.action;
 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 }

到此所有的开发以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.



Crying 2007-09-04 17:35 发表评论
]]>
Spring IOChttp://www.aygfsteel.com/Crying/articles/142028.htmlCryingCryingSun, 02 Sep 2007 01:10:00 GMThttp://www.aygfsteel.com/Crying/articles/142028.htmlhttp://www.aygfsteel.com/Crying/comments/142028.htmlhttp://www.aygfsteel.com/Crying/articles/142028.html#Feedback0http://www.aygfsteel.com/Crying/comments/commentRss/142028.htmlhttp://www.aygfsteel.com/Crying/services/trackbacks/142028.html假设我们要设计一个Girl和一个Boyc,其中Girl有kissҎQ即Girl惌Kiss一个Boy。那么,我们的问题是QGirl如何能够认识q个BoyQ?
在我们中国,常见的MM与GG的认识方式有以下几种
1 青梅竚wQ?2 亲友介绍Q?3 父母包办
那么哪一U才是最好呢Q?
青梅竚wQGirl从小q道自qBoy?
public class Girl {
void kiss(){
Boy boy = new Boy();
}
}
然而从开始就创徏的Boy~点是无法在更换。ƈ且要负责Boy的整个生命周期。如果我们的Girl惌换一个怎么办?Q严重不支持Girll常更换Boy,#_#Q?
亲友介绍Q由中间责提供Boy来见?
public class Girl {
void kiss(){
Boy boy = BoyFactory.createBoy();
}
}
亲友介绍Q固然是好。如果不满意Q尽另外换一个好了。但是,亲友BoyFactoryl常是以Singleton的Ş式出玎ͼ不然是Q存在于GlobalsQ无处不在,无处不能。实在是太繁琐了一点,不够灉|。我Z么一定要q个亲友掺和q来呢?Z么一定要付给她介l费呢?万一最好的朋友׃了我的男朋友呢?
父母包办Q一切交l父母,自己不用费吹C力,只需要等着Kiss好了?
public class Girl {
void kiss(Boy boy){
// kiss boy
boy.kiss();
}
}
WellQ这是对Girl最好的ҎQ只要想办法贿赂了Girl的父母,q把Boy交给他。那么我们就可以L的和Girl来Kiss了。看来几千年传统的父母之命还真是有用哦。至Boy和Girl不用自己瞎忙乎了?
q就是IOCQ将对象的创建和获取提取到外部。由外部容器提供需要的lg?
我们知道好莱坞原则:“Do not call us, we will call you.” 意思就是,You, girlie, do not call the boy. We will feed you a boy?
我们q应该知道依赖倒{原则?Dependence Inversion PrincinpleQDIP
Eric Gamma_要面向抽象编E。面向接口编E是面向对象的核心?
lg应该分ؓ两部分,?Service, 所提供功能的声?Implementation, Service的实?
好处是:多实现可以Q意切换,防止 “everything depends on everything” 问题Q即具体依赖于具体?
所以,我们的Boy应该是实现Kissable接口。这样一旦Girl不想kiss可恶的Boy的话Q还可以kiss可爱的kitten和慈的grandmother?


Crying 2007-09-02 09:10 发表评论
]]>
Spring?/title><link>http://www.aygfsteel.com/Crying/articles/142027.html</link><dc:creator>Crying</dc:creator><author>Crying</author><pubDate>Sun, 02 Sep 2007 01:08:00 GMT</pubDate><guid>http://www.aygfsteel.com/Crying/articles/142027.html</guid><wfw:comment>http://www.aygfsteel.com/Crying/comments/142027.html</wfw:comment><comments>http://www.aygfsteel.com/Crying/articles/142027.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/Crying/comments/commentRss/142027.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/Crying/services/trackbacks/142027.html</trackback:ping><description><![CDATA[    <div><font size="3">Spring 框架</font> </div> <div><font size="3">Spring 框架是一个分层架构,?7 个定义良好的模块l成。Spring 模块构徏在核心容器之上,核心容器定义了创建、配|和理 bean 的方式,如图 1 所C?/font> </div> <div>­</div> <div><strong><font size="3">?1. Spring 框架?7 个模?/font></strong> </div> <div><font size="3"><img height="288" src="http://www.ibm.com/developerworks/cn/java/wa-spring1/spring_framework.gif" width="555" border="0" alt="" /> </div> <div></font></div> <div><font size="3">l成 Spring 框架的每个模块(或组Ӟ都可以单独存在,或者与其他一个或多个模块联合实现。每个模块的功能如下Q?</font><font size="3"></font></div> <div><font size="3"><strong>核心容器</strong>Q核心容器提?Spring 框架的基本功能。核心容器的主要lg?BeanFactoryQ它是工厂模式的实现。BeanFactory 使用<em>控制反{</em> QIOCQ?模式应用程序的配置和依赖性规范与实际的应用程序代码分开?</font></div> <div><font size="3"></font></div> <div><font size="3"><strong>Spring 上下?/strong>QSpring 上下文是一个配|文Ӟ?Spring 框架提供上下文信息。Spring 上下文包括企业服务,例如 JNDI、EJB、电子邮件、国际化、校验和调度功能?</font></div> <div><font size="3"></font></div> <div><font size="3"><strong>Spring AOP</strong>Q通过配置理Ҏ,Spring AOP 模块直接面向方面的~程功能集成C Spring 框架中。所以,可以很容易地?Spring 框架理的Q何对象支?AOP。Spring AOP 模块为基?Spring 的应用程序中的对象提供了事务理服务。通过使用 Spring AOPQ不用依?EJB lgQ就可以声明性事务管理集成到应用E序中?</font></div> <div><font size="3"></font></div> <div><font size="3"><strong>Spring DAO</strong>QJDBC DAO 抽象层提供了有意义的异常层次l构Q可用该l构来管理异常处理和不同数据库供应商抛出的错误消息。异常层ơ结构简化了错误处理Qƈ且极大地降低了需要编写的异常代码数量Q例如打开和关闭连接)。Spring DAO 的面?JDBC 的异帔R从通用?DAO 异常层次l构?</font></div> <div><font size="3"></font></div> <div><font size="3"><strong>Spring ORM</strong>QSpring 框架插入了若q个 ORM 框架Q从而提供了 ORM 的对象关pdP其中包括 JDO、Hibernate ?iBatis SQL Map。所有这些都遵从 Spring 的通用事务?DAO 异常层次l构?</font></div> <div><font size="3"></font></div> <div><font size="3"><strong>Spring Web 模块</strong>QWeb 上下文模块徏立在应用E序上下文模块之上,为基?Web 的应用程序提供了上下文。所以,Spring 框架支持?Jakarta Struts 的集成。Web 模块q简化了处理多部分请求以及将h参数l定到域对象的工作?</font></div> <div><font size="3"></font></div> <div><font size="3"><strong>Spring MVC 框架</strong>QMVC 框架是一个全功能的构?Web 应用E序?MVC 实现。通过{略接口QMVC 框架变成为高度可配置的,MVC 容纳了大量视图技术,其中包括 JSP、Velocity、Tiles、iText ?POI?</font></div> <div>­</div> <div><font size="3">Spring 框架的功能可以用在Q?J2EE 服务器中Q大多数功能也适用于不受管理的环境。Spring 的核心要ҎQ支持不l定到特?J2EE 服务的可重用业务和数据访问对象。毫无疑问,q样的对象可以在不同 J2EE 环境 QWeb ?EJBQ、独立应用程序、测试环境之间重用?</font></div> <div>­</div> <div><img src="http://www.ibm.com/i/v14/rules/blue_rule.gif" border="0" alt="" /> </div> <div><img height="6" src="http://www.ibm.com/i/c.gif" width="8" border="0" alt="" /> </div> <div>­</div> <div>­</div> <div><font size="3">IOC ?AOP</font> </div> <div><font size="3">控制反{模式Q也UC依赖性介入)的基本概忉|Q不创徏对象Q但是描q创建它们的方式。在代码中不直接与对象和服务q接Q但在配|文件中描述哪一个组仉要哪一Ҏ务。容?Q在 Spring 框架中是 IOC 容器Q?负责这些联pd一赗?/font> </div> <div><font size="3">在典型的 IOC 场景中,容器创徏了所有对象,q设|必要的属性将它们q接在一P军_什么时间调用方法。下表列Z IOC 的一个实现模式?/font> </div> <div>cd 1服务需要实C门的接口Q通过接口Q由对象提供q些服务Q可以从对象查询依赖性(例如Q需要的附加服务Q类?2通过 JavaBean 的属性(例如 setter ҎQ分配依赖性类?3依赖性以构造函数的形式提供Q不?JavaBean 属性的形式公开 </div> <div><font size="3">Spring 框架?IOC 容器采用cd 2 和类? 实现?/font> </div> <div><strong><font size="3">面向斚w的编E?/font></strong> </div> <div><font size="3"><em>面向斚w的编E?/em>Q即 AOPQ是一U编E技术,它允许程序员Ҏ切关注点或横切典型的职责分界U的行ؓQ例如日志和事务理Q进行模块化。AOP 的核心构造是<em>斚w</em>Q它那些媄响多个类的行为封装到可重用的模块中?/font> </div> <div><font size="3">AOP ?IOC 是补充性的技术,它们都运用模块化方式解决企业应用E序开发中的复杂问题。在典型的面向对象开发方式中Q可能要日志记录语句放在所有方法和 Java cM才能实现日志功能。在 AOP 方式中,可以反过来将日志服务<em>模块?/em>Qƈ以声明的方式它们应用到需要日志的lg上。当Ӟ优势是 Java cM需要知道日志服务的存在Q也不需要考虑相关的代码。所以,?Spring AOP ~写的应用程序代码是松散耦合的?/font> </div> <div><font size="3">AOP 的功能完全集成到?Spring 事务理、日志和其他各种Ҏ的上下文中?/font> </div> <div><font size="3">IOC 容器</font> </div> <div><font size="3">Spring 设计的核心是 org.springframework.beans 包,它的设计目标是与 JavaBean lg一起用。这个包通常不是qL接用,而是由服务器其用作其他多数功能的底层中介。下一个最高抽象?BeanFactory 接口Q它是工厂设计模式的实现Q允讔R过名称创徏和检索对象。BeanFactory 也可以管理对象之间的关系?/font> </div> <div><font size="3">BeanFactory 支持两个对象模型?/font> </div> <div><font size="3"><strong>单?/strong> 模型提供了具有特定名U的对象的共享实例,可以在查询时对其q行索。Singleton 是默认的也是最常用的对象模型。对于无状态服务对象很理想?</font><font size="3"><strong>原型</strong> 模型保每次索都会创建单独的对象。在每个用户都需要自q对象Ӟ原型模型最适合?</font><font size="3">bean 工厂的概忉| Spring 作ؓ IOC 容器的基。IOC 处理事情的责Q从应用程序代码{Ud框架。正如我在下一个示例中演示的那PSpring 框架使用 JavaBean 属性和配置数据来指出必设|的依赖关系?/font> </div> <div><font size="3"></div> <div></font>  </div> <img src ="http://www.aygfsteel.com/Crying/aggbug/142027.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/Crying/" target="_blank">Crying</a> 2007-09-02 09:08 <a href="http://www.aygfsteel.com/Crying/articles/142027.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss> <footer> <div class="friendship-link"> <a href="http://www.aygfsteel.com/" title="狠狠久久亚洲欧美专区_中文字幕亚洲综合久久202_国产精品亚洲第五区在线_日本免费网站视频">狠狠久久亚洲欧美专区_中文字幕亚洲综合久久202_国产精品亚洲第五区在线_日本免费网站视频</a> </div> </footer> վ֩ģ壺 <a href="http://" target="_blank">°</a>| <a href="http://" target="_blank">ʡ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">³</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">տ</a>| <a href="http://" target="_blank">ګ</a>| <a href="http://" target="_blank">ﶫ</a>| <a href="http://" target="_blank">ƽԶ</a>| <a href="http://" target="_blank">Ͽ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">΢ɽ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ƽ˳</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ɽ</a>| <a href="http://" target="_blank">̫</a>| <a href="http://" target="_blank">ǡ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">۶</a>| <a href="http://" target="_blank">̶</a>| <a href="http://" target="_blank">˼</a>| <a href="http://" target="_blank">̨</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ͷ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">Ρɽ</a>| <a href="http://" target="_blank">Ǩ</a>| <a href="http://" target="_blank">ͨ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">κ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">Ϫ</a>| <script> (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })(); </script> </body>