锘??xml version="1.0" encoding="utf-8" standalone="yes"?>96成人在线视频,97国产精品videossex,久热99视频在线观看http://www.aygfsteel.com/gordian25/category/31783.html鑸囦笘鐒$埈zh-cnSat, 31 May 2008 23:07:47 GMTSat, 31 May 2008 23:07:47 GMT60Simple Tutorial - Aspect Oriented Programming with Springhttp://www.aygfsteel.com/gordian25/articles/203478.html鏆撮洦钀借憠(Gordian)鏆撮洦钀借憠(Gordian)Wed, 28 May 2008 05:48:00 GMThttp://www.aygfsteel.com/gordian25/articles/203478.htmlhttp://www.aygfsteel.com/gordian25/comments/203478.htmlhttp://www.aygfsteel.com/gordian25/articles/203478.html#Feedback0http://www.aygfsteel.com/gordian25/comments/commentRss/203478.htmlhttp://www.aygfsteel.com/gordian25/services/trackbacks/203478.html1.add <aop:aspectj-autoproxy/> to spring config xml

2.create a class and add @Aspect at the class

package tutorial;

import org.aspectj.lang.annotation.Aspect;

@Aspect
@Component
public class SystemArchitecture {

}

3.declare a pointcut in the class

package tutorial;

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

@Aspect
@Component
public class SystemArchitecture {

 @Pointcut("execution(* execute(..))")
 public void executePointcut() {
 }

}

4.declare a before advise in the class and use the "executePointcut" pointcut

package tutorial;

import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;

@Aspect
@Component
public class SystemArchitecture {

 @Pointcut("execution(* execute(..))")
 public void executePointcut() {
 }

 @Before("executePointcut()")
 public void before() {
  System.out.println("Before");
 }

}


5.this is already match all class when run method-name is "execute" the advise will auto run at the method before
create a demo class

package tutorial;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Component;

@Component
public class Demo {

 public void execute() {
  System.out.println("hello world");
 }

 public static void main(String[] args) {
  ApplicationContext context = new ClassPathXmlApplicationContext(
    "applicationContext.xml");
  Demo demo = (Demo) context.getBean("demo");
  demo.execute();
 }

}


It will be output
Before
hello world


the applicationContext.xml

<?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:context="http://www.springframework.org/schema/context"
 xmlns:aop="http://www.springframework.org/schema/aop"
 xsi:schemaLocation="http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
           http://www.springframework.org/schema/aop
           http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
           http://www.springframework.org/schema/context
           http://www.springframework.org/schema/context/spring-context-2.5.xsd">

 <context:annotation-config />
 <context:component-scan base-package="tutorial" />
 <aop:aspectj-autoproxy />

</beans>


 



鏆撮洦钀借憠(Gordian) 2008-05-28 13:48 鍙戣〃璇勮
]]>
主站蜘蛛池模板: 伽师县| 牡丹江市| 格尔木市| 许昌县| 漳浦县| 筠连县| 尚志市| 枣阳市| 泸定县| 兴安盟| 浦城县| 大邑县| 鹤庆县| 新龙县| 甘孜县| 沅江市| 云安县| 湖南省| 英山县| 青浦区| 苏尼特右旗| 宜良县| 濉溪县| 合水县| 儋州市| 乌兰浩特市| 扎赉特旗| 家居| 海阳市| 靖江市| 凭祥市| 拜泉县| 应城市| 塔城市| 灵石县| 广安市| 眉山市| 南郑县| 金塔县| 仁怀市| 岳池县|