﻿<?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-随笔分类-AOP</title><link>http://www.blogjava.net/Good-Game/category/26564.html</link><description /><language>zh-cn</language><lastBuildDate>Fri, 09 May 2008 17:48:19 GMT</lastBuildDate><pubDate>Fri, 09 May 2008 17:48:19 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>CGLib 学习</title><link>http://www.blogjava.net/Good-Game/archive/2007/11/05/158192.html</link><dc:creator>G_G</dc:creator><author>G_G</author><pubDate>Mon, 05 Nov 2007 02:22:00 GMT</pubDate><guid>http://www.blogjava.net/Good-Game/archive/2007/11/05/158192.html</guid><wfw:comment>http://www.blogjava.net/Good-Game/comments/158192.html</wfw:comment><comments>http://www.blogjava.net/Good-Game/archive/2007/11/05/158192.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.blogjava.net/Good-Game/comments/commentRss/158192.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Good-Game/services/trackbacks/158192.html</trackback:ping><description><![CDATA[
		<b>看hbn 源代码 发现用了 CGlib 这就看看这个jar 。特留个文 ^_^(转）<font color="#0000ff">http://www.nirvanastudio.org/java/cglib-%E6%8C%87%E5%8D%97.html</font><br /><br /></b>CGlib 就2个例能说明一切  <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);">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);"> MyClass {<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);"> method() {<br />        System.out.println(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">MyClass.method()</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);"> method2() {<br />        System.out.println(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">MyClass.method2()</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />    }<br />}<br /></span></div><br />例1：<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);">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);"> net.sf.cglib.proxy.Enhancer;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> net.sf.cglib.proxy.MethodProxy;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> net.sf.cglib.proxy.MethodInterceptor;<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 /> <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 /> <br />        Enhancer enhancer </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);"> Enhancer();<br />         <br />       <font color="#006400">  //在这代理了 </font><br />        enhancer.setSuperclass(MyClass.</span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);">);<br />        enhancer.setCallback( </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> MethodInterceptorImpl() );<br /> <br />       <font color="#006400"> // 创造 代理 （动态扩展了MyClass类）</font><br />        MyClass my </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> (MyClass)enhancer.create();<br /> <br />        my.method();<br />    }<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);">static</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);"> MethodInterceptorImpl </span><span style="color: rgb(0, 0, 255);">implements</span><span style="color: rgb(0, 0, 0);"> MethodInterceptor {<br />        <br />        </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> Object intercept(Object obj, <br />                                Method method, <br />                                Object[] args, <br />                                MethodProxy proxy) </span><span style="color: rgb(0, 0, 255);">throws</span><span style="color: rgb(0, 0, 0);"> Throwable {<br /> <br />            System.out.println(method);<br /> <br />            proxy.invokeSuper(obj, args);<br /> <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);">null</span><span style="color: rgb(0, 0, 0);">;<br />        }<br />    }<br />}</span></div><br /><br />例2：<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);">import</span><span style="color: rgb(0, 0, 0);"> java.lang.reflect.Method;<br /><br /><br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> net.sf.cglib.proxy.Enhancer;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> net.sf.cglib.proxy.MethodProxy;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> net.sf.cglib.proxy.MethodInterceptor;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> net.sf.cglib.proxy.NoOp;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> net.sf.cglib.proxy.Callback;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> net.sf.cglib.proxy.CallbackFilter;<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);">class</span><span style="color: rgb(0, 0, 0);"> Main2 {<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);">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 /> <br />        Callback[] callbacks </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);">new</span><span style="color: rgb(0, 0, 0);"> Callback[] { </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> MethodInterceptorImpl(),  NoOp.INSTANCE };<br /> <br />        Enhancer enhancer </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);"> Enhancer();<br /> <br />        enhancer.setSuperclass(MyClass.</span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);">);<br />        enhancer.setCallbacks( callbacks );<br />        <font color="#006400">//添加 方法过滤器  返回1为不运行 2 为运行</font><br />        enhancer.setCallbackFilter( </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> CallbackFilterImpl() );<br /> <br /> <br />        MyClass my </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> (MyClass)enhancer.create();<br /> <br />        my.method();<br />        my.method2();<br />    }<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);">static</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);"> CallbackFilterImpl </span><span style="color: rgb(0, 0, 255);">implements</span><span style="color: rgb(0, 0, 0);"> CallbackFilter {<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);">int</span><span style="color: rgb(0, 0, 0);"> accept(Method method) {<br /> <br />            </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> ( method.getName().equals(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">method2</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);">return</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">;<br /> <br />            } </span><span style="color: rgb(0, 0, 255);">else</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);"> </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">;<br />            }<br />        }<br />    }<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);">static</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);"> MethodInterceptorImpl </span><span style="color: rgb(0, 0, 255);">implements</span><span style="color: rgb(0, 0, 0);"> MethodInterceptor {<br />        <br />        </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> Object intercept(Object obj, <br />                                Method method, <br />                                Object[] args, <br />                                MethodProxy proxy) </span><span style="color: rgb(0, 0, 255);">throws</span><span style="color: rgb(0, 0, 0);"> Throwable {<br /> <br />            System.out.println(method);<br /> <br />            </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> proxy.invokeSuper(obj, args);<br />        }<br />    }<br />}</span></div><br /><br />简单不 哈哈 比jdk 中的动态代理好用 ，那还要接口  不太方便 。<br /><img src ="http://www.blogjava.net/Good-Game/aggbug/158192.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-11-05 10:22 <a href="http://www.blogjava.net/Good-Game/archive/2007/11/05/158192.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>AOP 学习笔记</title><link>http://www.blogjava.net/Good-Game/archive/2007/10/18/153971.html</link><dc:creator>G_G</dc:creator><author>G_G</author><pubDate>Thu, 18 Oct 2007 10:16:00 GMT</pubDate><guid>http://www.blogjava.net/Good-Game/archive/2007/10/18/153971.html</guid><wfw:comment>http://www.blogjava.net/Good-Game/comments/153971.html</wfw:comment><comments>http://www.blogjava.net/Good-Game/archive/2007/10/18/153971.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.blogjava.net/Good-Game/comments/commentRss/153971.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Good-Game/services/trackbacks/153971.html</trackback:ping><description><![CDATA[如有错误大家多指教<br /><br /><b>1.call(* *(..)) 和 execution(* *(..)) 区别<br />  </b>call 和 execution 都为切面限定<br />  execution 进行切面添加只能在方法定义的开始和结束。如：<br />   <font color="#008000">&gt;&gt;&gt;AOP 添加</font><br />      public String getName(){<br />          System.out.println("G_G");<br />        return this.name ;<br />    }<br />   <font color="#006400">&gt;&gt;&gt;AOP 添加</font><br />  call进行切面添加没有限定。如：<br />    <font color="#008000">&gt;&gt;&gt;AOP 添加</font><br />      public String getName(){<br /><font color="#008000">          &gt;&gt;&gt;AOP 添加</font><br />          System.out.println("G_G");<br />          <font color="#008000">&gt;&gt;&gt;AOP 添加</font><br />        return this.name ;<br />    }<br />   <font color="#006400">&gt;&gt;&gt;AOP 添加<br /><br /></font><b><font face="Times New Roman"><span style="" twffan="done" lang="EN-US"><span style="" twffan="done"><span style="font-family: &quot;Times New Roman&quot;; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;" twffan="done">     </span></span></span><span twffan="done" lang="EN-US"><font size="3">2.this </font></span></font><font size="3"><span style="font-family: 宋体;" twffan="done">和</span><span twffan="done" lang="EN-US"><font face="Times New Roman">within</font></span><span style="font-family: 宋体;" twffan="done">的</span></font>区别<br /></b>   都为范围限定作用，如： within(Demo) &amp;&amp; execution( * *(..)) 在类Demo中的所有..<br />   <font size="3">区别是：this不能切静态,within没有<br /><br /> <b>3.cflow的作用</b></font><font size="3"><br />  我们从 1&gt;cflow( within(DD+) &amp;&amp; execution( * *(..)) )</font><font size="3"> 和 <br />         2&gt;within(DD+) &amp;&amp; execution( * *(..)) 的区别来看<br />  1与2的对比是在2的切入点下再加 aj 文件的方法 进行添加切入点。<br /><br /><b>4.方法添加</b><br />  如：Introduction Example例中的 CloneablePoint.aj <br />     Point类继承Clonable 添加 </font><font size="3">clone() 方法</font><font size="3"><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);">   declare parents: Point </span><span style="color: rgb(0, 0, 255);">implements</span><span style="color: rgb(0, 0, 0);"> Cloneable;<br /><br />   </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> Object Point.clone() </span><span style="color: rgb(0, 0, 255);">throws</span><span style="color: rgb(0, 0, 0);"> CloneNotSupportedException {<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);">super</span><span style="color: rgb(0, 0, 0);">.clone();<br />   }<br /><br />   point.clone()....<br /></span></div><br /></font><br /><p class="MsoNormal" style="margin: 0cm 0cm 0pt 60pt;"><font size="3"><span style="font-family: 宋体;" twffan="done"><br /></span></font></p><br />   <br /><br /><font color="#006400"><br /></font><img src ="http://www.blogjava.net/Good-Game/aggbug/153971.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-18 18:16 <a href="http://www.blogjava.net/Good-Game/archive/2007/10/18/153971.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>我的AOP学习(AspectJ) </title><link>http://www.blogjava.net/Good-Game/archive/2007/10/15/153023.html</link><dc:creator>G_G</dc:creator><author>G_G</author><pubDate>Mon, 15 Oct 2007 08:57:00 GMT</pubDate><guid>http://www.blogjava.net/Good-Game/archive/2007/10/15/153023.html</guid><wfw:comment>http://www.blogjava.net/Good-Game/comments/153023.html</wfw:comment><comments>http://www.blogjava.net/Good-Game/archive/2007/10/15/153023.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/Good-Game/comments/commentRss/153023.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Good-Game/services/trackbacks/153023.html</trackback:ping><description><![CDATA[学习拥有连贯 <br />在我刚认识 <a id="viewpost1_TitleUrl" class="singleposttitle" href="/Good-Game/archive/2007/10/09/151238.html">让 java 动态</a> 这种动态编译动态加载的几天后<br />对我一向不懂的 AOP 特别是 AspectJ 开窍了 （哈哈 那感觉好啊^_^）<br />下面我写出我刚对AOP的一些小练 <br /><br /><font color="#ffa500">1。目的<br /><font color="#000000">DAO中大量的 session的开和闭 不紧使代码成倍加，还及容易出错 <br />用 设计模式 </font></font><a id="viewpost1_TitleUrl" class="singleposttitle" href="/Good-Game/archive/2007/07/04/128143.html">hibernate 包装</a> 下大家好象有点接受不了（@_@!）<br />AOP就进入我的视线 但总没个切入点 <br /><br /><font color="#ffa500">2。原理<br /></font>其实<a id="viewpost1_TitleUrl" class="singleposttitle" href="/Good-Game/archive/2007/10/09/151238.html"> 让 java 动态</a> 就是那点东西 但IBM 包出个好用的框架 来 。<br /><br /><font color="#ffa500">3。代码说明<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="#006400">//*******************Dao.java ****************************</font></b><br />package</span><span style="color: rgb(0, 0, 0);"> tt;<br /><font color="#008000">//为了简单 session 看成是 真的session 哈 ^_^</font><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);"> Dao {<br />    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> String session </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);">close</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);">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);"> testDao(){<br />        System.out.println( </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">testDao in function : </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> session);<br />    }<br />    <br />    </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);">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);"> main(String[]args){<br />        Dao dao </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);"> Dao() ;<br />        dao.testDao();<br />        System.out.println(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">main in function : </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);">  dao.session);<br />    }<br />}<br /></span></div><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>--><font color="#ffa500"><span style="color: rgb(0, 0, 255);"><b><font color="#006400">//*****************List.</font></b></span></font><font color="#ffa500"><span style="color: rgb(0, 0, 255);"><b><font color="#006400">aj ****************************</font></b></span></font><br /><span style="color: rgb(0, 0, 255);">package</span><span style="color: rgb(0, 0, 0);"> tt;<br /><br /></span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> aspect List {<br />    <font color="#006400">//切点  范围声明  （Dao.testDao 归 readOnly切点管  ） </font><br />    pointcut readOnly(Dao dao):execution(</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);">Dao.testDao</span><span style="color: rgb(0, 0, 0);">*</span><span style="color: rgb(0, 0, 0);">(..))</span><span style="color: rgb(0, 0, 0);">&amp;&amp;</span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">(dao);<br /><br />    <font color="#0000ff"><font color="#008000">//挂载 </font></font></span><font color="#ffa500"><span style="color: rgb(0, 0, 0);"><font color="#006400">readOnly</font></span></font><span style="color: rgb(0, 0, 0);"><font color="#0000ff"><font color="#008000"> 开始方法 </font></font><br />     before(Dao dao) :  readOnly(dao) {         <br />             openSession(dao);<br />      }<br /></span><font><font color="#ffa500"><span style="color: rgb(0, 0, 0);"><font color="#0000ff"><font color="#008000">     //挂载 </font></font></span><font color="#ffa500"><span style="color: rgb(0, 0, 0);"><font color="#006400">readOnly</font></span></font><span style="color: rgb(0, 0, 0);"><font color="#0000ff"><font color="#008000"> 结束方法 </font></font></span></font></font><br /><span style="color: rgb(0, 0, 0);">     after(Dao dao) returning()  :  readOnly(dao) {<br />          close(dao);<br />     }<br />     <br />     </span><font><font color="#ffa500"><span style="color: rgb(0, 0, 0);"><font color="#0000ff"><font color="#008000">// </font></font></span><font color="#ffa500"><span style="color: rgb(0, 0, 0);"><font color="#006400">readOnly</font></span></font><span style="color: rgb(0, 0, 0);"><font color="#0000ff"><font color="#008000"> 方法 运行代码 （到这可以大胆的写 java 代码了 ） 。。。。</font></font></span></font></font><br /><span style="color: rgb(0, 0, 0);">     </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);"> openSession(Dao dao) {<br />         </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(dao.session.equals(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">close</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">))<br />             dao.session </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);">Session Open</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);"> close(Dao dao) {<br />         dao.session </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);">close</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> ;<br />     }<br />}<br /></span></div><br />4。结果：<br /><b><font color="#000000">testDao in function : Session Open<br />main in function : close</font></b><br /><br /><br />4。后续<br /><font color="#000000">AspectJ 使 AOP 简单 <br />可能还会统一标准 <br />能为我们的java 框架灵活 更上一层 （期待）<br /><br /></font></font><br /><img src ="http://www.blogjava.net/Good-Game/aggbug/153023.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-15 16:57 <a href="http://www.blogjava.net/Good-Game/archive/2007/10/15/153023.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>