锘??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲AV无码成人精品区在线观看 ,亚洲中文字幕无码不卡电影,在线aⅴ亚洲中文字幕http://www.tkk7.com/Good-Game/category/26564.htmlzh-cnFri, 09 May 2008 17:48:19 GMTFri, 09 May 2008 17:48:19 GMT60spring 涓?hibernate 鏁村悎(浜嬪姟)http://www.tkk7.com/Good-Game/archive/2008/05/09/199477.htmlG_GG_GFri, 09 May 2008 05:47:00 GMThttp://www.tkk7.com/Good-Game/archive/2008/05/09/199477.htmlhttp://www.tkk7.com/Good-Game/comments/199477.htmlhttp://www.tkk7.com/Good-Game/archive/2008/05/09/199477.html#Feedback0http://www.tkk7.com/Good-Game/comments/commentRss/199477.htmlhttp://www.tkk7.com/Good-Game/services/trackbacks/199477.htmlhttp://doc.javanb.com/spring-framework-reference-zh-2-0-5/ch09.html

鍏堜粠閰嶇疆鏂囦歡寮濮嬶細
婧愮爜錛?a href="/Files/Good-Game/springAop.rar">springAop.rar

闇瑕乯ar
<?xml聽version="1.0"聽encoding="UTF-8"?>
<classpath>
聽聽聽聽
<classpathentry聽kind="src"聽path="java"/>
聽聽聽聽
<classpathentry聽kind="con"聽path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
聽聽聽聽
<classpathentry聽kind="lib"聽path="lib/aspectjrt.jar"/>
聽聽聽聽
<classpathentry聽kind="lib"聽path="lib/aspectjweaver.jar"/>
聽聽聽聽
<classpathentry聽kind="lib"聽path="lib/spring.jar"/>
聽聽聽聽
<classpathentry聽kind="lib"聽path="lib/spring-sources.jar"/>
聽聽聽聽
<classpathentry聽kind="lib"聽path="lib/commons-logging-1.0.4.jar"/>
聽聽聽聽
<classpathentry聽kind="lib"聽path="lib/cglib-nodep-2.1_3.jar"/>
聽聽聽聽
<classpathentry聽kind="lib"聽path="lib/hibernate3.jar"/>
聽聽聽聽
<classpathentry聽kind="lib"聽path="lib/log4j-1.2.11.jar"/>
聽聽聽聽
<classpathentry聽kind="con"聽path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
聽聽聽聽
<classpathentry聽kind="lib"聽path="lib/dom4j-1.6.1.jar"/>
聽聽聽聽
<classpathentry聽kind="lib"聽path="lib/commons-collections-2.1.1.jar"/>
聽聽聽聽
<classpathentry聽kind="lib"聽path="lib/mysql.jar"/>
聽聽聽聽
<classpathentry聽kind="lib"聽path="lib/jta.jar"/>
聽聽聽聽
<classpathentry聽kind="lib"聽path="lib/antlr-2.7.6.jar"/>
聽聽聽聽
<classpathentry聽kind="output"聽path="bin"/>
</classpath>


spring 閰嶇疆
<?xml聽version="1.0"聽encoding="UTF-8"?>
<beans聽xmlns="http://www.springframework.org/schema/beans"
聽聽聽聽聽聽聽xmlns:xsi
="http://www.w3.org/2001/XMLSchema-instance"
聽聽聽聽聽聽聽xmlns:aop
="http://www.springframework.org/schema/aop"
聽聽聽聽聽聽聽xmlns:tx
="http://www.springframework.org/schema/tx"
聽聽聽聽聽聽聽xsi:schemaLocation
="
聽聽聽聽聽聽聽http://www.springframework.org/schema/beans聽http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
聽聽聽聽聽聽聽http://www.springframework.org/schema/tx聽http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
聽聽聽聽聽聽聽http://www.springframework.org/schema/aop聽http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"
>
聽聽聽聽聽聽聽
聽聽
聽聽
<!--聽daoCalss聽:聽extends聽HibernateDaoSupport聽implements聽BeanDao聽-->
聽聽
<bean聽id="beanDao"聽class="dao.imp.BeanDaoImp">
聽聽聽聽聽聽
<property聽name="sessionFactory">
聽聽聽聽聽聽聽聽聽聽
<ref聽bean="sessionFactory"></ref>
聽聽聽聽聽聽
</property>
聽聽
</bean>
聽聽
聽聽聽
聽聽聽
<!--聽hibernate3聽sessionFactory聽-->
聽聽聽
<bean聽id="sessionFactory"聽聽聽聽聽
聽聽聽聽聽聽聽聽class
="org.springframework.orm.hibernate3.LocalSessionFactoryBean">聽聽
聽聽聽 聽聽聽
<!-- spring 涓?hibernate 鑱旂郴 -->
聽聽聽聽聽聽聽
<property聽name="configLocation"聽value="classpath:hibernate.cfg.xml"/>聽聽
聽聽聽
</bean>聽聽
聽聽聽
聽聽聽
<!--聽aop聽涓庝簨鍔¤仈緋宦燼opBean<->txAdvice聽聽-->
聽聽聽
<aop:config>
聽聽聽聽聽聽聽聽聽聽聽
<!--聽閫昏緫鎷︽埅聽-->
聽聽聽聽聽聽聽聽聽
<aop:pointcut聽id="aopBean"聽expression="execution(*聽*.*.*(..))"/>
聽聽聽聽聽聽聽聽聽聽聽
<aop:advisor聽advice-ref="txAdvice"聽pointcut-ref="aopBean"/>
聽聽聽聽聽聽
</aop:config>

聽聽聽聽
<!--聽浜嬪姟閫傞厤鍣?/span>-->
聽聽聽聽聽聽聽
<bean聽id="txManager"聽class="org.springframework.orm.hibernate3.HibernateTransactionManager">
聽聽聽聽聽聽
<property聽name="sessionFactory"聽ref="sessionFactory"/>
聽聽聽聽
</bean>

聽聽聽聽
<!--聽浜嬪姟鍘熷瓙聽鍏蜂綋鏂規硶榪涜浠涔堜簨鍔÷?/span>-->
聽聽聽聽聽聽
<tx:advice聽id="txAdvice"聽transaction-manager="txManager">
聽聽聽聽聽聽聽聽聽聽聽
<tx:attributes>
聽聽聽聽聽聽聽聽聽聽聽聽聽
<tx:method聽name="get*"聽read-only="true"/>
聽聽聽聽聽聽聽聽聽聽
<tx:method聽name="*"/>
聽聽聽聽聽聽聽聽
</tx:attributes>
聽聽聽聽聽聽
</tx:advice>

</beans>


hibernate 閰嶇疆
<?xml聽version="1.0"聽encoding="UTF-8"?>
<!DOCTYPE聽hibernate-configuration聽PUBLIC
聽聽聽聽聽聽聽聽"-//Hibernate/Hibernate聽Configuration聽DTD聽3.0//EN"
聽聽聽聽聽聽聽聽"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"
>
<hibernate-configuration>
<session-factory聽name="asdf">
聽聽聽聽
<property聽name="hibernate.dialect">mysql</property>
聽聽聽聽
<property聽name="myeclipse.connection.profile">
聽聽聽聽聽聽聽聽com.mysql.jdbc.Driver
聽聽聽聽
</property>
聽聽聽聽
<property聽name="connection.url">
聽聽聽聽聽聽聽聽jdbc:mysql://localhost/aop
聽聽聽聽
</property>
聽聽聽聽
<property聽name="show_sql">true</property>
聽聽聽聽
聽聽聽聽
<property聽name="connection.username">root</property>
聽聽聽聽
<property聽name="connection.password"></property>
聽聽聽聽
<property聽name="connection.driver_class">
聽聽聽聽聽聽聽聽com.mysql.jdbc.Driver
聽聽聽聽
</property>
聽聽聽聽
<property聽name="dialect">
聽聽聽聽聽聽聽聽org.hibernate.dialect.MySQLDialect
聽聽聽聽
</property>
聽聽聽聽
聽聽聽聽
<mapping聽resource="bean/UnitBean.hbm.xml"/>
聽聽聽聽
</session-factory>
</hibernate-configuration>


dao 綾伙紙鎺ュ彛錛?br />
package聽dao.imp;

import聽java.util.List;

import聽org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import聽bean.UnitBean;

import聽dao.BeanDao;

publicclass聽BeanDaoImp聽extends聽HibernateDaoSupport聽implements聽BeanDao{
聽聽聽聽
publicvoid聽addBean(UnitBean聽unitBean)聽{
聽聽聽聽聽聽聽聽
this.getHibernateTemplate().save(unitBean);
聽聽聽聽}

聽聽聽聽
public聽List<UnitBean>聽getBeanByAll()聽{
聽聽聽聽聽聽聽聽
returnthis.getHibernateTemplate().find("聽from聽"+UnitBean.class.getName());
聽聽聽聽}

聽聽聽聽
publicvoid聽removeBean(long聽beanId)聽{
聽聽聽聽聽聽聽聽
this.getHibernateTemplate().delete(
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽getHibernateTemplate().get(UnitBean.
class,聽beanId)
聽聽聽聽聽聽聽聽聽聽聽聽);
聽聽聽聽}
聽聽聽聽
}

Main 綾?br />
package聽unit;

import聽org.springframework.context.ApplicationContext;
import聽org.springframework.context.support.ClassPathXmlApplicationContext;

import聽dao.BeanDao;
import聽bean.UnitBean;

publicclass聽Main聽{
聽聽聽聽
publicstaticvoid聽main(String[]聽args)聽{
聽聽聽聽聽聽聽聽聽聽聽ApplicationContext聽ctx聽
=new聽ClassPathXmlApplicationContext("beans.xml");
聽聽聽聽聽聽聽聽聽聽聽BeanDao聽dao聽
=聽(BeanDao)聽ctx.getBean("beanDao");
聽聽聽聽聽聽聽聽聽聽聽UnitBean聽bean聽
=new聽UnitBean();
聽聽聽聽聽聽聽聽聽聽聽bean.setName(
"xx");
聽聽聽聽聽聽聽聽聽聽聽bean.setPass(
"11");
聽聽聽聽聽聽聽聽聽聽聽dao.addBean(bean);
聽聽聽聽聽聽聽聽聽聽聽
聽聽聽聽聽聽聽聽聽聽聽
for(UnitBean聽unitBean聽:聽dao.getBeanByAll()聽){
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽System.out.println(聽unitBean.getId()聽);
聽聽聽聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽聽聽聽
聽聽聽聽聽聽聽聽聽聽聽dao.removeBean(bean.getId());
聽聽聽聽聽聽聽聽聽聽聽
聽聽聽聽}
}
緇撴灉錛?br />Hibernate: insert into bean (name, pass) values (?, ?)
Hibernate: select unitbean0_.id as id0_, unitbean0_.name as name0_, unitbean0_.pass as pass0_ from bean unitbean0_
1
Hibernate: select unitbean0_.id as id0_0_, unitbean0_.name as name0_0_, unitbean0_.pass as pass0_0_ from bean unitbean0_ where unitbean0_.id=?
Hibernate: delete from bean where id=?








G_G 2008-05-09 13:47 鍙戣〃璇勮
]]>
spring AspectJ 鍩烘湰浣跨敤http://www.tkk7.com/Good-Game/archive/2008/05/08/199146.htmlG_GG_GThu, 08 May 2008 02:08:00 GMThttp://www.tkk7.com/Good-Game/archive/2008/05/08/199146.htmlhttp://www.tkk7.com/Good-Game/comments/199146.htmlhttp://www.tkk7.com/Good-Game/archive/2008/05/08/199146.html#Feedback0http://www.tkk7.com/Good-Game/comments/commentRss/199146.htmlhttp://www.tkk7.com/Good-Game/services/trackbacks/199146.htmlspring 瀹為檯浣跨敤 錛堣繖灝變嬌鐢ㄤ竴涓緥瀛愯鏄庯級

嫻嬭瘯綾諱互鍙婄粨鏋滐細
package聽unit;

import聽org.springframework.context.ApplicationContext;
import聽org.springframework.context.support.ClassPathXmlApplicationContext;

import聽bean.HelloService;

publicclass聽Main聽{
聽聽聽聽
publicstaticvoid聽main(String[]聽args)聽{
聽聽聽聽聽聽聽聽聽聽聽ApplicationContext聽context聽
=new聽ClassPathXmlApplicationContext(聽聽聽聽聽聽
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽
"beans.xml");聽聽聽聽
聽聽聽聽聽聽聽聽聽聽聽HelloService聽service聽
=聽(HelloService)聽context.getBean("helloService");聽聽聽聽
聽聽聽聽聽聽聽聽聽聽聽service.annotationAop();
聽聽聽聽聽聽聽聽聽聽聽
聽聽聽聽聽聽聽聽聽聽聽System.out.println();
聽聽聽聽聽聽聽聽聽聽聽
聽聽聽聽聽聽聽聽聽聽聽service.xmlAop();
聽聽聽聽聽聽聽聽聽聽聽
聽聽聽聽}
}
緇撴灉錛?/b>
聽annotationAop//姝e父鏂規硶榪愯
aop--AspectJ!聽//
annotation鎷︽埅

聽xmlAop
//姝e父鏂規硶榪愯
aop--XmlAop! //閰嶇疆鎷︽埅



use jar
  • --aspectjrt.jar
  • --aspectjweaver.jar
  • --acglib-nodep-2.1_3.jar
  • --commons-logging.jar
  • --spring.jar
  • --spring-aspects.jar
XML閰嶇疆
<beans聽xmlns="http://www.springframework.org/schema/beans"聽聽聽聽聽聽聽
聽聽聽聽聽聽聽聽聽聽聽聽xmlns:xsi
="http://www.w3.org/2001/XMLSchema-instance"
聽聽聽聽聽聽聽聽聽聽聽聽xmlns:aop
="http://www.springframework.org/schema/aop"
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽xsi:schemaLocation
=聽聽聽聽聽聽聽聽
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽"http://www.springframework.org/schema/beans聽聽聽聽聽聽聽聽聽
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽http://www.springframework.org/schema/beans/spring-beans.xsd聽聽聽聽聽聽聽聽聽
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽http://www.springframework.org/schema/aop聽聽聽聽聽聽聽聽聽
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽http://www.springframework.org/schema/aop/spring-aop.xsd"
>
聽聽聽聽聽聽聽聽
聽聽聽聽聽聽聽聽
<!--聽嫻嬭瘯浣跨敤綾宦犲垎鍒敱聽鏂規硶聽annotationAop/xmlAop聽-->
聽聽聽聽聽聽聽聽
<bean聽id="helloService"聽聽聽聽聽聽聽
聽聽聽聽聽聽聽聽聽聽聽聽class
="bean.HelloService"/>聽聽聽聽
聽聽聽聽聽聽聽聽
聽聽聽聽聽聽聽聽聽聽聽聽
聽聽聽聽聽聽聽聽
<!--聽annotation聽aop聽鎷︽埅聽浣跨敤@Aspect聽
聽聽聽聽聽聽聽聽聽聽聽聽@Pointcut("execution(*聽annotationAop(..))")聽聽
聽聽聽聽聽聽聽聽聽聽聽聽@AfterReturning("mainMethod()")聽聽
聽聽聽聽聽聽聽聽
-->
聽聽聽聽聽聽聽聽
<bean聽id="xmlAop"
聽聽聽聽聽聽聽聽聽聽聽聽class
="aop.AnnotationAspectJ"/>
聽聽聽聽聽聽聽聽
<aop:aspectj-autoproxy/>聽聽聽聽
聽聽聽聽聽聽聽聽
聽聽聽聽聽聽聽聽
聽聽聽聽聽聽聽聽
<!--聽xml聽aop聽聽閰嶇疆鏂囦歡鎷︽埅聽-->
聽聽聽聽聽聽聽聽
<bean聽id="XmlAspectJ"聽聽聽聽聽聽聽
聽聽聽聽聽聽聽聽聽聽聽聽class
="aop.XmlAspectJ"/>
聽聽聽聽聽聽聽聽
<aop:config>聽聽聽聽聽
聽聽聽聽聽聽聽聽聽聽聽聽聽
<aop:aspect聽ref="XmlAspectJ">
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽
<aop:pointcut聽id="mainMethod"聽expression="execution(*聽xmlAop(..))"/>聽聽聽聽
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽
<aop:after-returning聽pointcut-ref="mainMethod"聽method="goXmlAop"/>聽聽聽聽聽
聽聽聽聽聽聽聽聽聽聽聽聽聽
</aop:aspect>聽聽聽
聽聽聽聽聽聽聽聽聽
</aop:config>聽聽聽聽
聽聽聽聽聽聽聽聽聽聽聽聽
</beans>

HelloService.java
package聽bean;

publicclass聽HelloService聽{聽聽
聽聽聽聽
publicvoid聽annotationAop()聽{聽聽聽聽
聽聽聽聽聽聽聽聽System.out.println(
"聽annotationAop聽");
聽聽聽聽}
聽聽聽聽
聽聽聽聽
publicvoid聽xmlAop(){
聽聽聽聽聽聽聽聽System.out.println(
"聽xmlAop聽");
聽聽聽聽}
}

AnnotationAspectJ.java
package聽aop;

import聽org.aspectj.lang.annotation.AfterReturning;
import聽org.aspectj.lang.annotation.Aspect;
import聽org.aspectj.lang.annotation.Pointcut;

@Aspect
publicclass聽AnnotationAspectJ聽{聽聽
聽聽聽聽@Pointcut(
"execution(*聽annotationAop(..))")聽聽
聽聽聽聽
publicvoid聽mainMethod()聽{}聽聽
聽聽聽聽
聽聽聽聽@AfterReturning(
"mainMethod()")聽聽
聽聽聽聽
publicvoid聽sayHello()聽{聽聽聽聽
聽聽聽聽聽聽聽聽System.out.println(
"aop--AspectJ!");聽聽
聽聽聽聽}
}

XmlAspectJ.java
package聽aop;

publicclass聽XmlAspectJ聽{
聽聽聽聽
publicvoid聽goXmlAop(){
聽聽聽聽聽聽聽聽System.out.println(
"聽aop--XmlAop!聽");
聽聽聽聽}
}















G_G 2008-05-08 10:08 鍙戣〃璇勮
]]>
CGLib 瀛︿範http://www.tkk7.com/Good-Game/archive/2007/11/05/158192.htmlG_GG_GMon, 05 Nov 2007 02:22:00 GMThttp://www.tkk7.com/Good-Game/archive/2007/11/05/158192.htmlhttp://www.tkk7.com/Good-Game/comments/158192.htmlhttp://www.tkk7.com/Good-Game/archive/2007/11/05/158192.html#Feedback2http://www.tkk7.com/Good-Game/comments/commentRss/158192.htmlhttp://www.tkk7.com/Good-Game/services/trackbacks/158192.html鐪媓bn 婧愪唬鐮?鍙戠幇鐢ㄤ簡 CGlib 榪欏氨鐪嬬湅榪欎釜jar 銆傜壒鐣欎釜鏂?^_^(杞級http://www.nirvanastudio.org/java/cglib-%E6%8C%87%E5%8D%97.html

CGlib 灝?涓緥鑳借鏄庝竴鍒嚶?
鍏堟槸浣跨敤綾宦? 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽
publicclass聽MyClass聽{

聽聽聽聽
publicvoid聽method()聽{
聽聽聽聽聽聽聽聽System.out.println(
"MyClass.method()");
聽聽聽聽}

聽聽聽聽
publicvoid聽method2()聽{
聽聽聽聽聽聽聽聽System.out.println(
"MyClass.method2()");
聽聽聽聽}
}

渚?錛?br />
import聽java.lang.reflect.Method;

import聽net.sf.cglib.proxy.Enhancer;
import聽net.sf.cglib.proxy.MethodProxy;
import聽net.sf.cglib.proxy.MethodInterceptor;

publicclass聽Main聽{

聽聽聽聽
publicstaticvoid聽main(String[]聽args)聽{

聽聽聽聽聽聽聽聽Enhancer聽enhancer聽
=new聽Enhancer();
聽聽聽 聽聽
聽聽聽 聽聽聽 //鍦ㄨ繖浠g悊浜?
聽聽聽聽聽聽聽聽enhancer.setSuperclass(MyClass.
class);
聽聽聽聽聽聽聽聽enhancer.setCallback(聽
new聽MethodInterceptorImpl()聽);

聽聽聽聽聽聽聽 // 鍒涢?浠g悊 錛堝姩鎬佹墿灞曚簡MyClass綾伙級
聽聽聽聽聽聽聽聽MyClass聽my聽
=聽(MyClass)enhancer.create();

聽聽聽聽聽聽聽聽my.method();
聽聽聽聽}

聽聽聽聽
privatestaticclass聽MethodInterceptorImpl聽implements聽MethodInterceptor聽{
聽聽聽聽聽聽聽聽
聽聽聽聽聽聽聽聽
public聽Object聽intercept(Object聽obj,聽
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽Method聽method,聽
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽Object[]聽args,聽
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽MethodProxy聽proxy)聽
throws聽Throwable聽{

聽聽聽聽聽聽聽聽聽聽聽聽System.out.println(method);

聽聽聽聽聽聽聽聽聽聽聽聽proxy.invokeSuper(obj,聽args);

聽聽聽聽聽聽聽聽聽聽聽聽
returnnull;
聽聽聽聽聽聽聽聽}
聽聽聽聽}
}


渚?錛?br />
import聽java.lang.reflect.Method;


import聽net.sf.cglib.proxy.Enhancer;
import聽net.sf.cglib.proxy.MethodProxy;
import聽net.sf.cglib.proxy.MethodInterceptor;
import聽net.sf.cglib.proxy.NoOp;
import聽net.sf.cglib.proxy.Callback;
import聽net.sf.cglib.proxy.CallbackFilter;


publicclass聽Main2聽{

聽聽聽聽
publicstaticvoid聽main(String[]聽args)聽{

聽聽聽聽聽聽聽聽Callback[]聽callbacks聽
=
聽聽聽聽聽聽聽聽聽聽聽聽
new聽Callback[]聽{聽new聽MethodInterceptorImpl(),聽聽NoOp.INSTANCE聽};

聽聽聽聽聽聽聽聽Enhancer聽enhancer聽
=new聽Enhancer();

聽聽聽聽聽聽聽聽enhancer.setSuperclass(MyClass.
class);
聽聽聽聽聽聽聽聽enhancer.setCallbacks(聽callbacks聽);
聽聽聽聽聽聽聽 //娣誨姞 鏂規硶榪囨護鍣?榪斿洖1涓轟笉榪愯 2 涓鴻繍琛?/font>
聽聽聽聽聽聽聽聽enhancer.setCallbackFilter(聽
new聽CallbackFilterImpl()聽);


聽聽聽聽聽聽聽聽MyClass聽my聽
=聽(MyClass)enhancer.create();

聽聽聽聽聽聽聽聽my.method();
聽聽聽聽聽聽聽聽my.method2();
聽聽聽聽}

聽聽聽聽
privatestaticclass聽CallbackFilterImpl聽implements聽CallbackFilter聽{

聽聽聽聽聽聽聽聽
publicint聽accept(Method聽method)聽{

聽聽聽聽聽聽聽聽聽聽聽聽
if聽(聽method.getName().equals("method2")聽)聽{
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽
return1;

聽聽聽聽聽聽聽聽聽聽聽聽}聽
else聽{
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽
return0;
聽聽聽聽聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽}
聽聽聽聽}

聽聽聽聽
privatestaticclass聽MethodInterceptorImpl聽implements聽MethodInterceptor聽{
聽聽聽聽聽聽聽聽
聽聽聽聽聽聽聽聽
public聽Object聽intercept(Object聽obj,聽
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽Method聽method,聽
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽Object[]聽args,聽
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽MethodProxy聽proxy)聽
throws聽Throwable聽{

聽聽聽聽聽聽聽聽聽聽聽聽System.out.println(method);

聽聽聽聽聽聽聽聽聽聽聽聽
return聽proxy.invokeSuper(obj,聽args);
聽聽聽聽聽聽聽聽}
聽聽聽聽}
}


綆鍗曚笉 鍝堝搱 姣攋dk 涓殑鍔ㄦ佷唬鐞嗗ソ鐢?錛岄偅榪樿鎺ュ彛聽 涓嶅お鏂逛究 銆?br />

G_G 2007-11-05 10:22 鍙戣〃璇勮
]]>
AOP 瀛︿範絎旇http://www.tkk7.com/Good-Game/archive/2007/10/18/153971.htmlG_GG_GThu, 18 Oct 2007 10:16:00 GMThttp://www.tkk7.com/Good-Game/archive/2007/10/18/153971.htmlhttp://www.tkk7.com/Good-Game/comments/153971.htmlhttp://www.tkk7.com/Good-Game/archive/2007/10/18/153971.html#Feedback3http://www.tkk7.com/Good-Game/comments/commentRss/153971.htmlhttp://www.tkk7.com/Good-Game/services/trackbacks/153971.html
1.call(* *(..)) 鍜?execution(* *(..)) 鍖哄埆
call 鍜?execution 閮戒負鍒囬潰闄愬畾
聽 execution 榪涜鍒囬潰娣誨姞鍙兘鍦ㄦ柟娉曞畾涔夌殑寮濮嬪拰緇撴潫銆傚錛?br />聽聽 >>>AOP 娣誨姞
聽 聽聽聽 public String getName(){
聽 聽聽聽 聽聽聽 System.out.println("G_G");
聽聽聽 聽聽聽 return this.name ;
聽聽聽 }
聽聽 >>>AOP 娣誨姞
聽 call榪涜鍒囬潰娣誨姞娌℃湁闄愬畾銆傚錛?br />聽聽聽 >>>AOP 娣誨姞
聽 聽聽聽 public String getName(){
聽聽聽聽聽聽聽聽聽 >>>AOP 娣誨姞
聽 聽聽聽 聽聽聽 System.out.println("G_G");
聽聽聽聽聽聽聽聽聽 >>>AOP 娣誨姞
聽聽聽 聽聽聽 return this.name ;
聽聽聽 }
聽聽 >>>AOP 娣誨姞

聽聽聽聽 2.this 鍜?/span>within鐨?/span>鍖哄埆
聽聽 閮戒負鑼冨洿闄愬畾浣滅敤錛屽錛?within(Demo) && execution( * *(..)) 鍦ㄧ被Demo涓殑鎵鏈?.
聽聽 鍖哄埆鏄細this涓嶈兘鍒囬潤鎬?within娌℃湁

3.cflow鐨勪綔鐢?/b>

聽 鎴戜滑浠?1>cflow( within(DD+) && execution( * *(..)) )
鍜?
聽聽聽聽聽聽聽聽 2>within(DD+) && execution( * *(..)) 鐨勫尯鍒潵鐪?br />聽 1涓?鐨勫姣旀槸鍦?鐨勫垏鍏ョ偣涓嬪啀鍔?aj 鏂囦歡鐨勬柟娉?榪涜娣誨姞鍒囧叆鐐廣?br />
4.鏂規硶娣誨姞
聽 濡傦細Introduction Example渚嬩腑鐨?CloneablePoint.aj
聽聽聽聽 Point綾葷戶鎵緾lonable 娣誨姞
clone() 鏂規硶
聽聽聽declare聽parents:聽Point聽implements聽Cloneable;

聽聽聽
public聽Object聽Point.clone() throws聽CloneNotSupportedException聽{
聽聽聽聽聽聽
returnsuper.clone();
聽聽聽}

聽聽 point.clone()....




聽聽




G_G 2007-10-18 18:16 鍙戣〃璇勮
]]>
鎴戠殑AOP瀛︿範(AspectJ) http://www.tkk7.com/Good-Game/archive/2007/10/15/153023.htmlG_GG_GMon, 15 Oct 2007 08:57:00 GMThttp://www.tkk7.com/Good-Game/archive/2007/10/15/153023.htmlhttp://www.tkk7.com/Good-Game/comments/153023.htmlhttp://www.tkk7.com/Good-Game/archive/2007/10/15/153023.html#Feedback0http://www.tkk7.com/Good-Game/comments/commentRss/153023.htmlhttp://www.tkk7.com/Good-Game/services/trackbacks/153023.html鍦ㄦ垜鍒氳璇?璁?java 鍔ㄦ?/a> 榪欑鍔ㄦ佺紪璇戝姩鎬佸姞杞界殑鍑犲ぉ鍚?br />瀵規垜涓鍚戜笉鎳傜殑 AOP 鐗瑰埆鏄?AspectJ 寮紿嶄簡 錛堝搱鍝?閭f劅瑙夊ソ鍟奮_^錛?br />涓嬮潰鎴戝啓鍑烘垜鍒氬AOP鐨勪竴浜涘皬緇?

1銆傜洰鐨?br />DAO涓ぇ閲忕殑 session鐨勫紑鍜岄棴 涓嶇揣浣夸唬鐮佹垚鍊嶅姞錛岃繕鍙婂鏄撳嚭閿?
鐢?璁捐妯″紡
hibernate 鍖呰 涓嬪ぇ瀹跺ソ璞℃湁鐐規帴鍙椾笉浜嗭紙@_@!錛?br />AOP灝辮繘鍏ユ垜鐨勮綰?浣嗘繪病涓垏鍏ョ偣

2銆傚師鐞?br />鍏跺疄 璁?java 鍔ㄦ?/a> 灝辨槸閭g偣涓滆タ 浣咺BM 鍖呭嚭涓ソ鐢ㄧ殑妗嗘灦 鏉?銆?br />
3銆備唬鐮佽鏄?br />
//*******************Dao.java ****************************
package
聽tt;
//涓轟簡綆鍗?session 鐪嬫垚鏄?鐪熺殑session 鍝?^_^
publicclass聽Dao聽{
聽聽聽聽
public聽String聽session聽="close"聽;聽
聽聽聽聽
聽聽聽聽
publicvoid聽testDao(){
聽聽聽聽聽聽聽聽System.out.println(聽
"testDao聽in聽function聽:聽"+聽session);
聽聽聽聽}
聽聽聽聽
聽聽聽聽
staticpublicvoid聽main(String[]args){
聽聽聽聽聽聽聽聽Dao聽dao聽
=new聽Dao()聽;
聽聽聽聽聽聽聽聽dao.testDao();
聽聽聽聽聽聽聽聽System.out.println(
"main聽in聽function聽:聽"+聽聽dao.session);
聽聽聽聽}
}

//*****************List.aj ****************************
package聽tt;

public聽aspect聽List聽{
聽聽聽 //鍒囩偣聽 鑼冨洿澹版槑聽 錛圖ao.testDao 褰?readOnly鍒囩偣綆÷?錛?
聽聽聽聽pointcut聽readOnly(Dao聽dao):execution(
**Dao.testDao*(..))&&this(dao);

聽聽聽聽//鎸傝澆
readOnly 寮濮嬫柟娉?
聽聽聽聽聽before(Dao聽dao)聽:聽聽readOnly(dao)聽{聽聽聽聽聽聽聽聽聽
聽聽聽聽聽聽聽聽聽聽聽聽聽openSession(dao);
聽聽聽聽聽聽}
聽聽聽聽 //鎸傝澆 readOnly 緇撴潫鏂規硶
聽聽聽聽聽after(Dao聽dao)聽returning()聽聽:聽聽readOnly(dao)聽{
聽聽聽聽聽聽聽聽聽聽close(dao);
聽聽聽聽聽}
聽聽聽聽
聽聽聽聽
// readOnly 鏂規硶 榪愯浠g爜 錛堝埌榪欏彲浠ュぇ鑳嗙殑鍐?java 浠g爜浜?錛?銆傘傘傘?/font>
聽聽聽聽聽privatevoid聽openSession(Dao聽dao)聽{
聽聽聽聽聽聽聽聽聽
if(dao.session.equals("close"))
聽聽聽聽聽聽聽聽聽聽聽聽聽dao.session聽
="Session聽Open";
聽聽聽聽聽}
聽聽聽聽聽
privatevoid聽close(Dao聽dao)聽{
聽聽聽聽聽聽聽聽聽dao.session聽
="close"聽;
聽聽聽聽聽}
}

4銆傜粨鏋滐細
testDao in function : Session Open
main in function : close



4銆傚悗緇?br />AspectJ 浣?AOP 綆鍗?
鍙兘榪樹細緇熶竴鏍囧噯
鑳戒負鎴戜滑鐨刯ava 妗嗘灦鐏墊椿 鏇翠笂涓灞?錛堟湡寰咃級




G_G 2007-10-15 16:57 鍙戣〃璇勮
]]>
主站蜘蛛池模板: 日本亚洲欧洲免费天堂午夜看片女人员| 亚洲&#228;v永久无码精品天堂久久 | 在线观看人成视频免费无遮挡| 全部免费国产潢色一级| 亚洲精品无码一区二区| 成人性生免费视频| 亚洲老熟女五十路老熟女bbw| 国内免费高清在线观看| 亚洲中文精品久久久久久不卡| 午夜宅男在线永久免费观看网| 亚洲第一成人在线| 午夜一级免费视频| 色偷偷亚洲男人天堂| 成人亚洲综合天堂| 一个人晚上在线观看的免费视频| 久久久久亚洲AV无码专区网站| 三级网站免费观看| 麻豆亚洲av熟女国产一区二| 综合在线免费视频| 亚洲人成电影网站色| 免费国产怡红院在线观看| 三级网站免费观看| 亚洲国产一区在线观看| 免费观看毛片视频| 国产免费MV大全视频网站| 亚洲av综合avav中文| 五月婷婷综合免费| 在线观看亚洲视频| 久久久亚洲精品国产| 男人的好看免费观看在线视频| 亚洲av成人一区二区三区观看在线 | 亚洲国产aⅴ成人精品无吗| 亚洲伊人成无码综合网| 久操视频在线免费观看| 亚洲国产乱码最新视频| 亚洲精品成a人在线观看| 老司机69精品成免费视频| 亚洲日本久久一区二区va| jjzz亚洲亚洲女人| 免费女人高潮流视频在线观看| 亚洲六月丁香婷婷综合|