﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-Skynet-随笔分类-Spring</title><link>http://www.blogjava.net/Good-Game/category/26410.html</link><description /><language>zh-cn</language><lastBuildDate>Sat, 10 May 2008 06:02:41 GMT</lastBuildDate><pubDate>Sat, 10 May 2008 06:02:41 GMT</pubDate><ttl>60</ttl><item><title>spring 与 hibernate 整合(事务)</title><link>http://www.blogjava.net/Good-Game/archive/2008/05/09/199477.html</link><dc:creator>G_G</dc:creator><author>G_G</author><pubDate>Fri, 09 May 2008 05:47:00 GMT</pubDate><guid>http://www.blogjava.net/Good-Game/archive/2008/05/09/199477.html</guid><wfw:comment>http://www.blogjava.net/Good-Game/comments/199477.html</wfw:comment><comments>http://www.blogjava.net/Good-Game/archive/2008/05/09/199477.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/Good-Game/comments/commentRss/199477.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Good-Game/services/trackbacks/199477.html</trackback:ping><description><![CDATA[参考：第 9 章 事务管理 - Spring Framework  reference 2.0.5  参考手册中文版<br /><font color="#0000ff">http://doc.javanb.com/spring-framework-reference-zh-2-0-5/ch09.html</font><br /><br />先从配置文件开始：<br />源码：<a href="/Files/Good-Game/springAop.rar">springAop.rar</a><br /><br />需要jar<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 255);">&lt;?</span><span style="color: rgb(255, 0, 255);">xml version="1.0" encoding="UTF-8"</span><span style="color: rgb(0, 0, 255);">?&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">classpath</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">classpathentry </span><span style="color: rgb(255, 0, 0);">kind</span><span style="color: rgb(0, 0, 255);">="src"</span><span style="color: rgb(255, 0, 0);"> path</span><span style="color: rgb(0, 0, 255);">="java"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">classpathentry </span><span style="color: rgb(255, 0, 0);">kind</span><span style="color: rgb(0, 0, 255);">="con"</span><span style="color: rgb(255, 0, 0);"> path</span><span style="color: rgb(0, 0, 255);">="org.eclipse.jdt.launching.JRE_CONTAINER"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">classpathentry </span><span style="color: rgb(255, 0, 0);">kind</span><span style="color: rgb(0, 0, 255);">="lib"</span><span style="color: rgb(255, 0, 0);"> path</span><span style="color: rgb(0, 0, 255);">="lib/aspectjrt.jar"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">classpathentry </span><span style="color: rgb(255, 0, 0);">kind</span><span style="color: rgb(0, 0, 255);">="lib"</span><span style="color: rgb(255, 0, 0);"> path</span><span style="color: rgb(0, 0, 255);">="lib/aspectjweaver.jar"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">classpathentry </span><span style="color: rgb(255, 0, 0);">kind</span><span style="color: rgb(0, 0, 255);">="lib"</span><span style="color: rgb(255, 0, 0);"> path</span><span style="color: rgb(0, 0, 255);">="lib/spring.jar"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">classpathentry </span><span style="color: rgb(255, 0, 0);">kind</span><span style="color: rgb(0, 0, 255);">="lib"</span><span style="color: rgb(255, 0, 0);"> path</span><span style="color: rgb(0, 0, 255);">="lib/spring-sources.jar"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">classpathentry </span><span style="color: rgb(255, 0, 0);">kind</span><span style="color: rgb(0, 0, 255);">="lib"</span><span style="color: rgb(255, 0, 0);"> path</span><span style="color: rgb(0, 0, 255);">="lib/commons-logging-1.0.4.jar"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">classpathentry </span><span style="color: rgb(255, 0, 0);">kind</span><span style="color: rgb(0, 0, 255);">="lib"</span><span style="color: rgb(255, 0, 0);"> path</span><span style="color: rgb(0, 0, 255);">="lib/cglib-nodep-2.1_3.jar"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">classpathentry </span><span style="color: rgb(255, 0, 0);">kind</span><span style="color: rgb(0, 0, 255);">="lib"</span><span style="color: rgb(255, 0, 0);"> path</span><span style="color: rgb(0, 0, 255);">="lib/hibernate3.jar"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">classpathentry </span><span style="color: rgb(255, 0, 0);">kind</span><span style="color: rgb(0, 0, 255);">="lib"</span><span style="color: rgb(255, 0, 0);"> path</span><span style="color: rgb(0, 0, 255);">="lib/log4j-1.2.11.jar"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">classpathentry </span><span style="color: rgb(255, 0, 0);">kind</span><span style="color: rgb(0, 0, 255);">="con"</span><span style="color: rgb(255, 0, 0);"> path</span><span style="color: rgb(0, 0, 255);">="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">classpathentry </span><span style="color: rgb(255, 0, 0);">kind</span><span style="color: rgb(0, 0, 255);">="lib"</span><span style="color: rgb(255, 0, 0);"> path</span><span style="color: rgb(0, 0, 255);">="lib/dom4j-1.6.1.jar"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">classpathentry </span><span style="color: rgb(255, 0, 0);">kind</span><span style="color: rgb(0, 0, 255);">="lib"</span><span style="color: rgb(255, 0, 0);"> path</span><span style="color: rgb(0, 0, 255);">="lib/commons-collections-2.1.1.jar"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">classpathentry </span><span style="color: rgb(255, 0, 0);">kind</span><span style="color: rgb(0, 0, 255);">="lib"</span><span style="color: rgb(255, 0, 0);"> path</span><span style="color: rgb(0, 0, 255);">="lib/mysql.jar"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">classpathentry </span><span style="color: rgb(255, 0, 0);">kind</span><span style="color: rgb(0, 0, 255);">="lib"</span><span style="color: rgb(255, 0, 0);"> path</span><span style="color: rgb(0, 0, 255);">="lib/jta.jar"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">classpathentry </span><span style="color: rgb(255, 0, 0);">kind</span><span style="color: rgb(0, 0, 255);">="lib"</span><span style="color: rgb(255, 0, 0);"> path</span><span style="color: rgb(0, 0, 255);">="lib/antlr-2.7.6.jar"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">classpathentry </span><span style="color: rgb(255, 0, 0);">kind</span><span style="color: rgb(0, 0, 255);">="output"</span><span style="color: rgb(255, 0, 0);"> path</span><span style="color: rgb(0, 0, 255);">="bin"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">classpath</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span></div><br /><br /><font color="#a52a2a">spring 配置<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 255);">&lt;?</span><span style="color: rgb(255, 0, 255);">xml version="1.0" encoding="UTF-8"</span><span style="color: rgb(0, 0, 255);">?&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">beans </span><span style="color: rgb(255, 0, 0);">xmlns</span><span style="color: rgb(0, 0, 255);">="http://www.springframework.org/schema/beans"</span><span style="color: rgb(255, 0, 0);"><br />       xmlns:xsi</span><span style="color: rgb(0, 0, 255);">="http://www.w3.org/2001/XMLSchema-instance"</span><span style="color: rgb(255, 0, 0);"><br />       xmlns:aop</span><span style="color: rgb(0, 0, 255);">="http://www.springframework.org/schema/aop"</span><span style="color: rgb(255, 0, 0);"><br />       xmlns:tx</span><span style="color: rgb(0, 0, 255);">="http://www.springframework.org/schema/tx"</span><span style="color: rgb(255, 0, 0);"><br />       xsi:schemaLocation</span><span style="color: rgb(0, 0, 255);">="<br />       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd<br />       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd<br />       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />       <br />  <br />  </span><span style="color: rgb(0, 128, 0);">&lt;!--</span><span style="color: rgb(0, 128, 0);"> daoCalss : extends HibernateDaoSupport implements BeanDao </span><span style="color: rgb(0, 128, 0);">--&gt;</span><span style="color: rgb(0, 0, 0);"><br />  </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">bean </span><span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">="beanDao"</span><span style="color: rgb(255, 0, 0);"> class</span><span style="color: rgb(0, 0, 255);">="dao.imp.BeanDaoImp"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />      </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">property </span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="sessionFactory"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />          </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">ref </span><span style="color: rgb(255, 0, 0);">bean</span><span style="color: rgb(0, 0, 255);">="sessionFactory"</span><span style="color: rgb(0, 0, 255);">&gt;&lt;/</span><span style="color: rgb(128, 0, 0);">ref</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />      </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">property</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />  </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">bean</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />  <br />   <br />   </span><span style="color: rgb(0, 128, 0);">&lt;!--</span><span style="color: rgb(0, 128, 0);"> hibernate3 sessionFactory </span><span style="color: rgb(0, 128, 0);">--&gt;</span><span style="color: rgb(0, 0, 0);"><br />   </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">bean </span><span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">="sessionFactory"</span><span style="color: rgb(255, 0, 0);">     <br />        class</span><span style="color: rgb(0, 0, 255);">="org.springframework.orm.hibernate3.LocalSessionFactoryBean"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">   <br />        </span><font><font color="#a52a2a"><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 128, 0);">&lt;!--</span><span style="color: rgb(0, 128, 0);"> spring 与 hibernate 联系 </span><span style="color: rgb(0, 128, 0);">--&gt;</span></font></font><span style="color: rgb(0, 0, 0);">   <br />       </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">property </span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="configLocation"</span><span style="color: rgb(255, 0, 0);"> value</span><span style="color: rgb(0, 0, 255);">="classpath:hibernate.cfg.xml"</span><span style="color: rgb(255, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);">  <br />   </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">bean</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">  <br />   <br />   </span><span style="color: rgb(0, 128, 0);">&lt;!--</span><span style="color: rgb(0, 128, 0);"> aop 与事务联系 aopBean&lt;-&gt;txAdvice  </span><span style="color: rgb(0, 128, 0);">--&gt;</span><span style="color: rgb(0, 0, 0);"><br />   </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">aop:config</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />           </span><span style="color: rgb(0, 128, 0);">&lt;!--</span><span style="color: rgb(0, 128, 0);"> 逻辑拦截 </span><span style="color: rgb(0, 128, 0);">--&gt;</span><span style="color: rgb(0, 0, 0);"><br />         </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">aop:pointcut </span><span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">="aopBean"</span><span style="color: rgb(255, 0, 0);"> expression</span><span style="color: rgb(0, 0, 255);">="execution(* *.*.*(..))"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br />           </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">aop:advisor </span><span style="color: rgb(255, 0, 0);">advice-ref</span><span style="color: rgb(0, 0, 255);">="txAdvice"</span><span style="color: rgb(255, 0, 0);"> pointcut-ref</span><span style="color: rgb(0, 0, 255);">="aopBean"</span><span style="color: rgb(255, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br />      </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">aop:config</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /><br />    </span><span style="color: rgb(0, 128, 0);">&lt;!--</span><span style="color: rgb(0, 128, 0);"> 事务适配器 </span><span style="color: rgb(0, 128, 0);">--&gt;</span><span style="color: rgb(0, 0, 0);"><br />       </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">bean </span><span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">="txManager"</span><span style="color: rgb(255, 0, 0);"> class</span><span style="color: rgb(0, 0, 255);">="org.springframework.orm.hibernate3.HibernateTransactionManager"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />      </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">property </span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="sessionFactory"</span><span style="color: rgb(255, 0, 0);"> ref</span><span style="color: rgb(0, 0, 255);">="sessionFactory"</span><span style="color: rgb(255, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">bean</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /><br />    </span><span style="color: rgb(0, 128, 0);">&lt;!--</span><span style="color: rgb(0, 128, 0);"> 事务原子 具体方法进行什么事务 </span><span style="color: rgb(0, 128, 0);">--&gt;</span><span style="color: rgb(0, 0, 0);"><br />      </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">tx:advice </span><span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">="txAdvice"</span><span style="color: rgb(255, 0, 0);"> transaction-manager</span><span style="color: rgb(0, 0, 255);">="txManager"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />           </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">tx:attributes</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />             </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">tx:method </span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="get*"</span><span style="color: rgb(255, 0, 0);"> read-only</span><span style="color: rgb(0, 0, 255);">="true"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br />          </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">tx:method </span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="*"</span><span style="color: rgb(255, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br />        </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">tx:attributes</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />      </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">tx:advice</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /><br /></span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">beans</span><span style="color: rgb(0, 0, 255);">&gt;</span></div><br /></font><br /><font color="#a52a2a"><b>hibernate 配置</b></font><br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 255);">&lt;?</span><span style="color: rgb(255, 0, 255);">xml version="1.0" encoding="UTF-8"</span><span style="color: rgb(0, 0, 255);">?&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 0, 255);">&lt;!</span><span style="color: rgb(255, 0, 255);">DOCTYPE hibernate-configuration PUBLIC<br />        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"<br />        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">hibernate-configuration</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">session-factory </span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="asdf"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">property </span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="hibernate.dialect"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">mysql</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">property</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">property </span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="myeclipse.connection.profile"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />        com.mysql.jdbc.Driver<br />    </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">property</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">property </span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="connection.url"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />        jdbc:mysql://localhost/aop<br />    </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">property</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">property </span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="show_sql"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">true</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">property</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />    <br />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">property </span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="connection.username"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">root</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">property</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">property </span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="connection.password"</span><span style="color: rgb(0, 0, 255);">&gt;&lt;/</span><span style="color: rgb(128, 0, 0);">property</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">property </span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="connection.driver_class"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />        com.mysql.jdbc.Driver<br />    </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">property</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">property </span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="dialect"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />        org.hibernate.dialect.MySQLDialect<br />    </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">property</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />    <br />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">mapping </span><span style="color: rgb(255, 0, 0);">resource</span><span style="color: rgb(0, 0, 255);">="bean/UnitBean.hbm.xml"</span><span style="color: rgb(255, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br />    <br /></span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">session-factory</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">hibernate-configuration</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span></div><br /><br />dao 类（接口）<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 255);">package</span><span style="color: rgb(0, 0, 0);"> dao.imp;<br /><br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> java.util.List;<br /><br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.springframework.orm.hibernate3.support.HibernateDaoSupport;<br /><br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> bean.UnitBean;<br /><br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> dao.BeanDao;<br /><br /></span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);"> BeanDaoImp </span><span style="color: rgb(0, 0, 255);">extends</span><span style="color: rgb(0, 0, 0);"> HibernateDaoSupport </span><span style="color: rgb(0, 0, 255);">implements</span><span style="color: rgb(0, 0, 0);"> BeanDao{<br />    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> addBean(UnitBean unitBean) {<br />        </span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.getHibernateTemplate().save(unitBean);<br />    }<br /><br />    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> List</span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">UnitBean</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"> getBeanByAll() {<br />        </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.getHibernateTemplate().find(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> from </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">UnitBean.</span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);">.getName());<br />    }<br /><br />    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> removeBean(</span><span style="color: rgb(0, 0, 255);">long</span><span style="color: rgb(0, 0, 0);"> beanId) {<br />        </span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.getHibernateTemplate().delete(<br />                getHibernateTemplate().get(UnitBean.</span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);">, beanId)<br />            );<br />    }<br />    <br />}<br /></span></div><br />Main 类<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 255);">package</span><span style="color: rgb(0, 0, 0);"> unit;<br /><br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.springframework.context.ApplicationContext;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.springframework.context.support.ClassPathXmlApplicationContext;<br /><br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> dao.BeanDao;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> bean.UnitBean;<br /><br /></span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);"> Main {<br />    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">static</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> main(String[] args) {<br />           ApplicationContext ctx </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> ClassPathXmlApplicationContext(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">beans.xml</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />           BeanDao dao </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> (BeanDao) ctx.getBean(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">beanDao</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />           UnitBean bean </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> UnitBean();<br />           bean.setName(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">xx</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />           bean.setPass(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">11</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />           dao.addBean(bean);<br />           <br />           </span><span style="color: rgb(0, 0, 255);">for</span><span style="color: rgb(0, 0, 0);">(UnitBean unitBean : dao.getBeanByAll() ){<br />               System.out.println( unitBean.getId() );<br />           }<br />           <br />           dao.removeBean(bean.getId());<br />           <br />    }<br />}<br /></span></div>结果：<br /><font color="#006400">Hibernate: insert into bean (name, pass) values (?, ?)<br />Hibernate: select unitbean0_.id as id0_, unitbean0_.name as name0_, unitbean0_.pass as pass0_ from bean unitbean0_<br />1<br />Hibernate: select unitbean0_.id as id0_0_, unitbean0_.name as name0_0_, unitbean0_.pass as pass0_0_ from bean unitbean0_ where unitbean0_.id=?<br />Hibernate: delete from bean where id=?<br /></font><br /><br /><br /><br /><br /><br /><img src ="http://www.blogjava.net/Good-Game/aggbug/199477.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Good-Game/" target="_blank">G_G</a> 2008-05-09 13:47 <a href="http://www.blogjava.net/Good-Game/archive/2008/05/09/199477.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>spring AspectJ 基本使用</title><link>http://www.blogjava.net/Good-Game/archive/2008/05/08/199146.html</link><dc:creator>G_G</dc:creator><author>G_G</author><pubDate>Thu, 08 May 2008 02:08:00 GMT</pubDate><guid>http://www.blogjava.net/Good-Game/archive/2008/05/08/199146.html</guid><wfw:comment>http://www.blogjava.net/Good-Game/comments/199146.html</wfw:comment><comments>http://www.blogjava.net/Good-Game/archive/2008/05/08/199146.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/Good-Game/comments/commentRss/199146.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Good-Game/services/trackbacks/199146.html</trackback:ping><description><![CDATA[我的aop 基础<br /><ul><li><a id="Singlecolumn2_Categories_CatList_ctl00_LinkList_ctl02_RssLink" title="Subscribe to AOP(3)" href="/Good-Game/category/26564.html/rss"><img title="Subscribe to AOP(3)" src="/Skins/KJC/Images/xmlsmall.gif" style="border-width: 0px;" /></a><a id="Singlecolumn2_Categories_CatList_ctl00_LinkList_ctl02_Link" href="/Good-Game/category/26564.html">AOP(3)</a></li></ul>spring 实际使用 （这就使用一个例子说明）<br /><span style="color: rgb(0, 0, 255);"><br />
测试类以及结果：<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 255);">package</span><span style="color: rgb(0, 0, 0);"> unit;<br /><br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.springframework.context.ApplicationContext;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.springframework.context.support.ClassPathXmlApplicationContext;<br /><br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> bean.HelloService;<br /><br /></span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);"> Main {<br />    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">static</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> main(String[] args) {<br />           ApplicationContext context </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> ClassPathXmlApplicationContext(      <br />                   </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">beans.xml</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);    <br />           HelloService service </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> (HelloService) context.getBean(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">helloService</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);    <br />           service.annotationAop();<br />           <br />           System.out.println();<br />           <br />           service.xmlAop();<br />           <br />    }<br />}<br /><font color="#a52a2a"><b>结果：</b></font><br /><font color="#0000ff"> annotationAop</font><font color="#006400">//正常方法运行</font><br /><font color="#0000ff">aop--AspectJ! </font><font color="#008000">//</font></span><font color="#008000"><span style="color: rgb(0, 0, 255);"><span style="color: rgb(0, 0, 0);">annotation</span></span></font><span style="color: rgb(0, 0, 0);"><font color="#008000">拦截 </font><br /><br /><font color="#0000ff"> xmlAop</font>  </span><span style="color: rgb(0, 0, 255);"><span style="color: rgb(0, 0, 0);">/<font color="#006400">/正常方法运行</font></span></span><br /><span style="color: rgb(0, 0, 0);"> <font color="#0000ff">aop--XmlAop! </font></span><span style="color: rgb(0, 0, 255);"><font color="#006400"><span style="color: rgb(0, 0, 0);">//</span><span style="color: rgb(0, 0, 255);"><span style="color: rgb(0, 0, 0);">配置</span></span></font><span style="color: rgb(0, 0, 0);"><font color="#006400">拦截</font></span></span></div><br /></span><br /><br /><b><font color="#00ee00"><font color="#008000"> use jar</font></font></b><ul><li><font color="#0000ff">--aspectjrt.jar</font></li><li><font color="#0000ff">--aspectjweaver.jar</font></li><li><font color="#0000ff">--acglib-nodep-2.1_3.jar</font></li><li><font color="#0000ff">--commons-logging.jar</font></li><li><font color="#0000ff">--spring.jar</font></li><li><font color="#0000ff">--spring-aspects.jar</font></li></ul><font color="#008000"><b>XML配置</b></font><br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">beans </span><span style="color: rgb(255, 0, 0);">xmlns</span><span style="color: rgb(0, 0, 255);">="http://www.springframework.org/schema/beans"</span><span style="color: rgb(255, 0, 0);">       <br />            xmlns:xsi</span><span style="color: rgb(0, 0, 255);">="http://www.w3.org/2001/XMLSchema-instance"</span><span style="color: rgb(255, 0, 0);"><br />            xmlns:aop</span><span style="color: rgb(0, 0, 255);">="http://www.springframework.org/schema/aop"</span><span style="color: rgb(255, 0, 0);"><br />               xsi:schemaLocation</span><span style="color: rgb(0, 0, 255);">=        <br />                   "http://www.springframework.org/schema/beans         <br />                   http://www.springframework.org/schema/beans/spring-beans.xsd         <br />                   http://www.springframework.org/schema/aop         <br />                   http://www.springframework.org/schema/aop/spring-aop.xsd"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />        <br />        </span><span style="color: rgb(0, 128, 0);">&lt;!--</span><span style="color: rgb(0, 128, 0);"> 测试使用类 分别由 方法 annotationAop/xmlAop </span><span style="color: rgb(0, 128, 0);">--&gt;</span><span style="color: rgb(0, 0, 0);"><br />        </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">bean </span><span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">="helloService"</span><span style="color: rgb(255, 0, 0);">       <br />            class</span><span style="color: rgb(0, 0, 255);">="bean.HelloService"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);">    <br />        <br />            <br />        </span><span style="color: rgb(0, 128, 0);">&lt;!--</span><span style="color: rgb(0, 128, 0);"> annotation aop 拦截 使用@Aspect <br />            @Pointcut("execution(* annotationAop(..))")  <br />            @AfterReturning("mainMethod()")  <br />        </span><span style="color: rgb(0, 128, 0);">--&gt;</span><span style="color: rgb(0, 0, 0);"><br />        </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">bean </span><span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">="xmlAop"</span><span style="color: rgb(255, 0, 0);"> <br />            class</span><span style="color: rgb(0, 0, 255);">="aop.AnnotationAspectJ"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br />        </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">aop:aspectj-autoproxy</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);">    <br />        <br />        <br />        </span><span style="color: rgb(0, 128, 0);">&lt;!--</span><span style="color: rgb(0, 128, 0);"> xml aop  配置文件拦截 </span><span style="color: rgb(0, 128, 0);">--&gt;</span><span style="color: rgb(0, 0, 0);"><br />        </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">bean </span><span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">="XmlAspectJ"</span><span style="color: rgb(255, 0, 0);">       <br />            class</span><span style="color: rgb(0, 0, 255);">="aop.XmlAspectJ"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br />        </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">aop:config</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">     <br />             </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">aop:aspect </span><span style="color: rgb(255, 0, 0);">ref</span><span style="color: rgb(0, 0, 255);">="XmlAspectJ"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />                 </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">aop:pointcut </span><span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">="mainMethod"</span><span style="color: rgb(255, 0, 0);"> expression</span><span style="color: rgb(0, 0, 255);">="execution(* xmlAop(..))"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);">    <br />                 </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">aop:after-returning </span><span style="color: rgb(255, 0, 0);">pointcut-ref</span><span style="color: rgb(0, 0, 255);">="mainMethod"</span><span style="color: rgb(255, 0, 0);"> method</span><span style="color: rgb(0, 0, 255);">="goXmlAop"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);">     <br />             </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">aop:aspect</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">   <br />         </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">aop:config</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">    <br />            <br /></span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">beans</span><span style="color: rgb(0, 0, 255);">&gt;</span></div><br /><span style="color: rgb(0, 0, 255);">HelloService.java<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 255);">package</span><span style="color: rgb(0, 0, 0);"> bean;<br /><br /></span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);"> HelloService {  <br />    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> annotationAop() {    <br />        System.out.println(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> annotationAop </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />    }<br />    <br />    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> xmlAop(){<br />        System.out.println(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> xmlAop </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />    }<br />}<br /></span></div><br /></span><span style="color: rgb(0, 0, 255);">AnnotationAspectJ.java<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 255);">package</span><span style="color: rgb(0, 0, 0);"> aop;<br /><br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.aspectj.lang.annotation.AfterReturning;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.aspectj.lang.annotation.Aspect;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.aspectj.lang.annotation.Pointcut;<br /><br />@Aspect<br /></span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);"> AnnotationAspectJ {  <br />    @Pointcut(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">execution(* annotationAop(..))</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">)  <br />    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> mainMethod() {}  <br />    <br />    @AfterReturning(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">mainMethod()</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">)  <br />    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> sayHello() {    <br />        System.out.println(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">aop--AspectJ!</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);  <br />    }<br />}<br /></span></div><br /></span><span style="color: rgb(0, 0, 255);">XmlAspectJ.java<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 255);">package</span><span style="color: rgb(0, 0, 0);"> aop;<br /><br /></span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);"> XmlAspectJ {<br />    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> goXmlAop(){<br />        System.out.println(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> aop--XmlAop! </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />    }<br />}<br /></span></div><br /><br /></span><span style="color: rgb(0, 0, 255);"><br /></span><span style="color: rgb(0, 0, 255);"><br /></span><br /><br /><br /><br /><br /><br /><br /><br /><br /><img src ="http://www.blogjava.net/Good-Game/aggbug/199146.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Good-Game/" target="_blank">G_G</a> 2008-05-08 10:08 <a href="http://www.blogjava.net/Good-Game/archive/2008/05/08/199146.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>spring 学习笔记</title><link>http://www.blogjava.net/Good-Game/archive/2007/12/21/169359.html</link><dc:creator>G_G</dc:creator><author>G_G</author><pubDate>Fri, 21 Dec 2007 08:33:00 GMT</pubDate><guid>http://www.blogjava.net/Good-Game/archive/2007/12/21/169359.html</guid><wfw:comment>http://www.blogjava.net/Good-Game/comments/169359.html</wfw:comment><comments>http://www.blogjava.net/Good-Game/archive/2007/12/21/169359.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/Good-Game/comments/commentRss/169359.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Good-Game/services/trackbacks/169359.html</trackback:ping><description><![CDATA[我 的 春天spring 正式开始 ！^_^<br />spring项目基本需要jar-&gt;commons-logging.jar;log4j-1.2.9.jar;spring.jar<br /><font color="#0000ff">参考：http://www.redsaga.com/spring_ref/2.0/html/beans.html<br /><br /><font color="#ffa500">本文主要内容：</font><br /><font color="#000000">1.单多配置文件的使用<br />2.动态替换类方法（cglib）<br />3.</font></font>自定义作用域bean<br />4.定制bean特性<br /><br /><br /><b><font color="#0000ff"><font color="#000000">1).单多配置文件的使用</font></font></b><br />1.1)配置文件:beans.xml格式（基本配置）<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 255);">&lt;?</span><span style="color: rgb(255, 0, 255);">xml version="1.0" encoding="UTF-8"</span><span style="color: rgb(0, 0, 255);">?&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 0, 255);">&lt;!</span><span style="color: rgb(255, 0, 255);">DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" <br />    "http://www.springframework.org/dtd/spring-beans.dtd"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">beans</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">bean </span><span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">="userBean"</span><span style="color: rgb(255, 0, 0);"> name</span><span style="color: rgb(0, 0, 255);">="userBean"</span><span style="color: rgb(255, 0, 0);"> <br />          class</span><span style="color: rgb(0, 0, 255);">="springtest.UserBean"</span><span style="color: rgb(255, 0, 0);"> <br />          abstract</span><span style="color: rgb(0, 0, 255);">="false"</span><span style="color: rgb(255, 0, 0);"> <br />          singleton</span><span style="color: rgb(0, 0, 255);">="true"</span><span style="color: rgb(255, 0, 0);"> <br />          lazy-init</span><span style="color: rgb(0, 0, 255);">="default"</span><span style="color: rgb(255, 0, 0);"><br />          autowire</span><span style="color: rgb(0, 0, 255);">="default"</span><span style="color: rgb(255, 0, 0);"> <br />          dependency-check</span><span style="color: rgb(0, 0, 255);">="default"</span><span style="color: rgb(255, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />            </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">property </span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="name"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />                </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">value</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">bea</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">value</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />            </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">property</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">bean</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />    <br /></span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">beans</span><span style="color: rgb(0, 0, 255);">&gt;</span></div><br />spring 工厂建立单配置和多配置文件<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">    <font color="#006400">//单配置文件加载</font></span><span style="color: rgb(0, 0, 255);"><br />    public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> testSp()</span><span style="color: rgb(0, 0, 255);">throws</span><span style="color: rgb(0, 0, 0);"> Exception{<br />        Resource res </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> FileSystemResource(<br />            </span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.getClass().getClassLoader().getResource(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">config/beans.xml</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">).getPath()<br />                );<br />        BeanFactory fac </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> XmlBeanFactory(res);<br />        UserBean uu </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> (UserBean) fac.getBean(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">userBean</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />        System.out.println(uu.getName());<br />        System.out.println(uu.getAge());<br />    }<br /></span><span style="color: rgb(0, 0, 0);">    <font color="#006400">//多配置文件加载</font></span><br /><span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> testSps() </span><span style="color: rgb(0, 0, 255);">throws</span><span style="color: rgb(0, 0, 0);"> Exception {<br />        ApplicationContext act</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> ClassPathXmlApplicationContext(<br />            </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> String[] {</span><font color="#a52a2a"><span style="color: rgb(0, 0, 0);">"</span><font color="#a52a2a"><span style="color: rgb(0, 0, 0);">config/beans.xml</span></font><span style="color: rgb(0, 0, 0);">"</span></font><span style="color: rgb(0, 0, 0);"><font color="#a52a2a">,.....</font>}<br />        );<br />        UserBean uu </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> (UserBean)act.getBean(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">userBean</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />        System.out.println( uu.getName());<br />    }</span></div>1.2) 还用一种是单配置多&lt;import resource="。.xml"/&gt;达到多配置<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 255);">&lt;?</span><span style="color: rgb(255, 0, 255);">xml version="1.0" encoding="UTF-8"</span><span style="color: rgb(0, 0, 255);">?&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 0, 255);">&lt;!</span><span style="color: rgb(255, 0, 255);">DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" <br />    "http://www.springframework.org/dtd/spring-beans.dtd"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">beans</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">import </span><span style="color: rgb(255, 0, 0);">resource</span><span style="color: rgb(0, 0, 255);">="beans_2.xml"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">bean </span><span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">="userBean"</span><span style="color: rgb(255, 0, 0);"> name</span><span style="color: rgb(0, 0, 255);">="userBean"</span><span style="color: rgb(255, 0, 0);"> <br />          class</span><span style="color: rgb(0, 0, 255);">="springtest.UserBean"</span><span style="color: rgb(255, 0, 0);"> <br />          abstract</span><span style="color: rgb(0, 0, 255);">="false"</span><span style="color: rgb(255, 0, 0);"> <br />          singleton</span><span style="color: rgb(0, 0, 255);">="true"</span><span style="color: rgb(255, 0, 0);"> <br />          lazy-init</span><span style="color: rgb(0, 0, 255);">="default"</span><span style="color: rgb(255, 0, 0);"><br />          autowire</span><span style="color: rgb(0, 0, 255);">="default"</span><span style="color: rgb(255, 0, 0);"> <br />          dependency-check</span><span style="color: rgb(0, 0, 255);">="default"</span><span style="color: rgb(255, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />            </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">property </span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="name"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />                </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">ref  </span><span style="color: rgb(255, 0, 0);">bean</span><span style="color: rgb(0, 0, 255);">="str1"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br />            </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">property</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">bean</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">beans</span><span style="color: rgb(0, 0, 255);">&gt;<br /><br />加载就用上的 -》</span><span style="color: rgb(0, 0, 0);"><font color="#006400">单配置文件加载</font></span></div><br /><b><font color="#0000ff"><font color="#000000">2).动态替换类方法（cglib）</font></font></b><br />配置文件中 替换方法(替换方法 <b>getName </b>) lib中加入 <b>cglib.jar</b><br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 255);">&lt;?</span><span style="color: rgb(255, 0, 255);">xml version="1.0" encoding="UTF-8"</span><span style="color: rgb(0, 0, 255);">?&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 0, 255);">&lt;!</span><span style="color: rgb(255, 0, 255);">DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" <br />    "http://www.springframework.org/dtd/spring-beans.dtd"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">beans</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">import </span><span style="color: rgb(255, 0, 0);">resource</span><span style="color: rgb(0, 0, 255);">="beans_2.xml"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">bean </span><span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">="userBean"</span><span style="color: rgb(255, 0, 0);"> name</span><span style="color: rgb(0, 0, 255);">="userBean"</span><span style="color: rgb(255, 0, 0);"> <br />          class</span><span style="color: rgb(0, 0, 255);">="springtest.UserBean"</span><span style="color: rgb(255, 0, 0);"> <br />          abstract</span><span style="color: rgb(0, 0, 255);">="false"</span><span style="color: rgb(255, 0, 0);"> <br />          singleton</span><span style="color: rgb(0, 0, 255);">="true"</span><span style="color: rgb(255, 0, 0);"> <br />          lazy-init</span><span style="color: rgb(0, 0, 255);">="default"</span><span style="color: rgb(255, 0, 0);"><br />          autowire</span><span style="color: rgb(0, 0, 255);">="default"</span><span style="color: rgb(255, 0, 0);"> <br />          dependency-check</span><span style="color: rgb(0, 0, 255);">="default"</span><span style="color: rgb(255, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /><b>              </b></span><b><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">replaced-method </span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="getName"</span><span style="color: rgb(255, 0, 0);"> replacer</span><span style="color: rgb(0, 0, 255);">="rm"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />                  </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">arg-type</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">String</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">arg-type</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />              </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">replaced-method</span><span style="color: rgb(0, 0, 255);">&gt;</span></b><span style="color: rgb(0, 0, 0);"><br />            </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">property </span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="name"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />                </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">ref  </span><span style="color: rgb(255, 0, 0);">bean</span><span style="color: rgb(0, 0, 255);">="str1"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br />            </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">property</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">bean</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />    <br />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">bean </span><span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">="rm"</span><span style="color: rgb(255, 0, 0);"> class</span><span style="color: rgb(0, 0, 255);">="springtest.ReplacedMethod"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">beans</span><span style="color: rgb(0, 0, 255);">&gt;</span></div><br /><span style="color: rgb(0, 0, 255);">springtest.ReplacedMethod类<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 255);">package</span><span style="color: rgb(0, 0, 0);"> springtest;<br /><br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> java.lang.reflect.Method;<br /><br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.springframework.beans.factory.support.MethodReplacer;<br /><br /></span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);"> ReplacedMethod </span><span style="color: rgb(0, 0, 255);">implements</span><span style="color: rgb(0, 0, 0);"> MethodReplacer {<br />    <br />    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> Object reimplement(Object arg0, Method arg1, Object[] arg2) </span><span style="color: rgb(0, 0, 255);">throws</span><span style="color: rgb(0, 0, 0);"> Throwable {<br />        </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 255);">刘凯毅</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">;<br />    }<br />}</span></div><br />结果： 不管你怎么setName getName出来的都是-》 “刘凯毅”<br /><br /></span><b><font color="#0000ff"><font color="#000000">3.</font></font>自定义作用域bean 需要jdk1.5<br /><br /><br />4.定制bean特性<br /></b>1）初始化回调 &lt;bean id=".." class=".." init-method="init"/&gt; 方法init()<br />  和 继承<tt class="literal">org.springframework.beans.factory.InitializingBean 实现接口方法 <br /></tt>    void afterPropertiesSet() throws Exception; 一样<br />2）<br /><br /><img src ="http://www.blogjava.net/Good-Game/aggbug/169359.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Good-Game/" target="_blank">G_G</a> 2007-12-21 16:33 <a href="http://www.blogjava.net/Good-Game/archive/2007/12/21/169359.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>为我学习 Spring AOP 准备（Proxy）</title><link>http://www.blogjava.net/Good-Game/archive/2007/10/09/151302.html</link><dc:creator>G_G</dc:creator><author>G_G</author><pubDate>Tue, 09 Oct 2007 03:13:00 GMT</pubDate><guid>http://www.blogjava.net/Good-Game/archive/2007/10/09/151302.html</guid><wfw:comment>http://www.blogjava.net/Good-Game/comments/151302.html</wfw:comment><comments>http://www.blogjava.net/Good-Game/archive/2007/10/09/151302.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.blogjava.net/Good-Game/comments/commentRss/151302.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Good-Game/services/trackbacks/151302.html</trackback:ping><description><![CDATA[为我准备学习和理解spring <br />特留下代码笔记：<br /><font color="#ffa500">参考：</font><br /><font color="#0000ff">http://dev.csdn.net/author/labile/e70c97cb7f504d35b7b5350e7810cc5a.html</font><br /><font color="#ffa500">代码感想：<br />    <font color="#000000">没个方法都或多或少需要环境参数(如: jdbc的conn ,hbn的session...等等 )，方法结束后又要关闭。<br />何不用proxy代理并用配置文件的方法来 关,开session 等<br />如：<font color="#ff1493">以下是我的想法并不是实际可用</font><br />    <div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 255);"><b><font color="#ffa500">配置：</font></b><br />&lt;</span><span style="color: rgb(128, 0, 0);">class </span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="</span><font color="#ffa500"><font color="#000000"><font><font><font color="#ffa500"><font color="#000000"><span style="color: rgb(0, 0, 255);">HelloWorldImpl</span></font></font></font></font></font></font><font color="#0000ff"><span style="color: rgb(0, 0, 0);"></span></font><span style="color: rgb(0, 0, 255);">"</span><span style="color: rgb(0, 0, 255);">&gt;<br />  </span><font><font><font color="#ffa500"><font color="#000000"><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">function </span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="set*"</span><span style="color: rgb(0, 0, 255);"> /&gt;</span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);"><br /><br /></span></font></font></font></font><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">  &lt;</span><span style="color: rgb(128, 0, 0);">function </span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="getName"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 0, 255);">    </span><font><font><font color="#ffa500"><font color="#000000"><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">proxyBegin artt="name"</span><span style="color: rgb(0, 0, 255);"></span><span style="color: rgb(255, 0, 0);"> value</span><span style="color: rgb(0, 0, 255);">="liukaiyi"</span><span style="color: rgb(0, 0, 255);">/&gt; <br />        <font color="#006400">//使用Proxy来赋值 name那在实现代码中就可以不用去关注象 session 等属性的开关了 <br />        //proxy中配置下 ， 在实现类中 就使用 就可以了 </font></span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);"></span></font></font></font></font><br /><span style="color: rgb(0, 0, 255);">    &lt;</span><span style="color: rgb(128, 0, 0);">proxyBegin </span><span style="color: rgb(255, 0, 0);">ref</span><span style="color: rgb(0, 0, 255);">="HelloWorldHandler.doBefter"</span><span style="color: rgb(255, 0, 0);"> args</span><span style="color: rgb(0, 0, 255);">="null"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 0, 255);">    &lt;</span><span style="color: rgb(128, 0, 0);">proxyEnd </span><span style="color: rgb(255, 0, 0);">ref</span><span style="color: rgb(0, 0, 255);">="HelloWorldHandler.doAfter"</span><span style="color: rgb(255, 0, 0);"> args</span><span style="color: rgb(0, 0, 255);">="null"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 0, 255);">  &lt;/</span><span style="color: rgb(128, 0, 0);">function</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /><br /></span><span style="color: rgb(0, 0, 255);">  &lt;</span><span style="color: rgb(128, 0, 0);">function </span><span style="color: rgb(0, 0, 255);">= name="sayHelloWorld"&gt;<br /></span><span style="color: rgb(255, 0, 0);">    &lt;proxyEnd ref</span><span style="color: rgb(0, 0, 255);">="HelloWorldHandler.doAfter"</span><span style="color: rgb(255, 0, 0);"> args</span><span style="color: rgb(0, 0, 255);">="null"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 0, 255);">  &lt;/</span><span style="color: rgb(128, 0, 0);">function</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">class</span><span style="color: rgb(0, 0, 255);">&gt;<br /><br /><b><font color="#ffa500">代码：</font></b><br /></span><font color="#ffa500"><font color="#000000"><font><font><font color="#ffa500"><font color="#000000"><span style="color: rgb(0, 0, 255);">HelloWorld hw = </span></font></font></font></font></font></font><span style="color: rgb(0, 0, 255);">(</span><font><font><font color="#ffa500"><font color="#000000"><span style="color: rgb(0, 0, 255);">HelloWorld</span></font></font></font></font><span style="color: rgb(0, 0, 255);">)Factory.getBean(</span><font><font><font color="#ffa500"><font color="#000000"><span style="color: rgb(0, 0, 255);">"HelloWorldImpl"</span></font></font></font></font><span style="color: rgb(0, 0, 255);">);<br />hw.getName();<br /><br /><b><font color="#ffa500">结果是：</font></b><br />before method invoke!<br />刘凯毅<br />after method invoke!<br /></span></div>在此 我只是想象，spring 还没有看，但我认为spring 这个著名的框架应该在这方面有很好的实现。<br /><br /><b><font color="#ffa500">实际代码：<font color="#ff1493">希望spring可以向我上面的方法配置好用来取代下面的实际代码 ^_^</font></font></b><br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 255);">package</span><span style="color: rgb(0, 0, 0);"> test.proxy;<br /><br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> java.lang.reflect.InvocationHandler;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> java.lang.reflect.Method;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> java.lang.reflect.Proxy;<br /><br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> junit.framework.TestCase;<br /><br /></span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);"> TestProxy </span><span style="color: rgb(0, 0, 255);">extends</span><span style="color: rgb(0, 0, 0);"> TestCase {<br />    <br />    </span><span style="color: rgb(0, 0, 255);">protected</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> setUp() </span><span style="color: rgb(0, 0, 255);">throws</span><span style="color: rgb(0, 0, 0);"> Exception {<br />        </span><span style="color: rgb(0, 0, 255);">super</span><span style="color: rgb(0, 0, 0);">.setUp();<br />    }<br />    <br />    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> testProxy(){<br />             HelloWorld hw </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> HelloWorldImpl();           <br />                       InvocationHandler handler </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> HelloWorldHandler(hw);          <br />                       HelloWorld proxy </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> (HelloWorld) Proxy.newProxyInstance(   <br />                                     hw.getClass().getClassLoader(),   <br />                                     hw.getClass().getInterfaces(),   <br />                                     handler);   <br />                       proxy.sayHelloWorld();<br />                       <br />                       System.out.println();<br />                       proxy.setName(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">liukaiyi</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />                       proxy.getName();<br />    }<br />    <br />}<br /><br /></span><span style="color: rgb(0, 0, 255);">interface</span><span style="color: rgb(0, 0, 0);"> HelloWorld {   <br />    </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> sayHelloWorld() ;   <br />    </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> getName();<br />    </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> setName(String name);<br />}<br /><br /></span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);"> HelloWorldImpl </span><span style="color: rgb(0, 0, 255);">implements</span><span style="color: rgb(0, 0, 0);"> HelloWorld {   <br />    </span><span style="color: rgb(0, 0, 255);">private</span><span style="color: rgb(0, 0, 0);"> String name </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">""</span><span style="color: rgb(0, 0, 0);">;<br />    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> setName(String name) {<br />        </span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.name </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> name;<br />    }<br /><br />    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> sayHelloWorld() {   <br />        System.out.println(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Hello World!</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);              <br />    }<br /><br />    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> getName() {<br />        System.out.println(</span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.name);<br />    }   <br />}<br /><br /></span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);"> HelloWorldHandler </span><span style="color: rgb(0, 0, 255);">implements</span><span style="color: rgb(0, 0, 0);"> InvocationHandler {   <br />            </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">要代理的原始对象   </span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">            </span><span style="color: rgb(0, 0, 255);">private</span><span style="color: rgb(0, 0, 0);"> Object objOriginal;   <br />            </span><span style="color: rgb(0, 128, 0);">/**</span><span style="color: rgb(0, 128, 0);">  <br />             * 构造函数。  <br />             * </span><span style="color: rgb(128, 128, 128);">@param</span><span style="color: rgb(0, 128, 0);"> obj 要代理的原始对象。  <br />             </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);">  <br />            </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> HelloWorldHandler(Object obj) {   <br />                   </span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.objOriginal </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> obj ;   <br />            }   <br />            </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> Object invoke(Object proxy, Method method, Object[] args)   <br />                          </span><span style="color: rgb(0, 0, 255);">throws</span><span style="color: rgb(0, 0, 0);"> Throwable {               <br />                   Object result </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);"> ;              <br />                   String meName </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> method.getName();<br />                   </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(meName.indexOf(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">set</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">)</span><span style="color: rgb(0, 0, 0);">&gt;-</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);"> ){<br />                       </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> method.invoke(</span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.objOriginal ,args);   <br />                   }<br />                   </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">( meName.equals(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">getName</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">) ){<br />                    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">方法调用之前   </span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">                           doBefore(); </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">仿佛是AOP的影子，呵呵   </span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">                   }<br />                     </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">调用原始对象的方法   </span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">                           result </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> method.invoke(</span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.objOriginal ,args);   <br />                     </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">方法调用之后   </span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">                           doAfter();       <br />                   <br />                   </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> result ;   <br />            }   <br />            </span><span style="color: rgb(0, 0, 255);">private</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> doBefore() {   <br />                   System.out.println(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">before method invoke!</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);   <br />            }   <br />            </span><span style="color: rgb(0, 0, 255);">private</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> doAfter() {   <br />                   System.out.println(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">after method invoke!</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);   <br />            }   <br />     }   <br /></span></div><br /><br /></font></font><font color="#ffa500">结果：<br /><font color="#000000">Hello World!<br />after method invoke!<br /><br />before method invoke!<br />刘凯毅<br />after method invoke!<br /></font><br /></font><img src ="http://www.blogjava.net/Good-Game/aggbug/151302.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Good-Game/" target="_blank">G_G</a> 2007-10-09 11:13 <a href="http://www.blogjava.net/Good-Game/archive/2007/10/09/151302.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>