스프링 AOP 포인트컷(pointcut),ControllFlowPointcut/포인트컷/Advisor/타겟클래스/위빙(자바동영…

스프링 AOP 포인트컷(pointcut),ControllFlowPointcut/포인트컷/Advisor/타겟클래스/위빙(자바동영상/스프링동영상/자바교육/스프링교육/스프링프레임워크/스프링학원/자바학원/자바/JAVA)  

 

포인트컷(Pointcut) - ControllFlowPointcut

 

n  특정 메소드 하위의 모든 메소드 호출 또는 특정 클래스 하위의 모든 메소드 호출에 사용한다

 

[First.java]

package onj.edu.aop7;

 

public class First {

 

           public void hello() {

                      // 특정 메소드인 myAdvice()에서 Call할 때 충고 적용함

                      System.out.println("hello ... ");

           }

}

 

[SimpleBeforeAdvice.java]

package onj.edu.aop7;

 

import java.lang.reflect.Method;

import org.springframework.aop.MethodBeforeAdvice;

 

public class SimpleBeforeAdvice implements MethodBeforeAdvice {

           public void before(Method method, Object args[], Object target) throws Throwable {

                      System.out.println("Before Method ::" + method);

           }

}

 

[ControlFlowExam.java]

 

public class CaontrolFlowExam {

           public static void main(String[] args) {

                      ControlFlowExam c = new ControlFlowExam();

                      c.go();

           }

           void go() {

                      First target = new First();

                      //ControlFlowExam.class myAdvice() 가 호출하는 모든 메소드에 충고적용

                      Pointcut pc = new ControlFlowPointcut(ControlFlowExam.class, "myAdvice");

                      Advisor advisor = new DefaultPointcutAdvisor(pc, new SimpleBeforeAdvice());

 

                      //Proxy

                      ProxyFactory pf = new ProxyFactory();

                      pf.setTarget(target);

                      pf.addAdvisors(advisor);

 

                      First f = (First)pf.getProxy();

                      //Normal Invoke

                      f.hello();

                      //ControlFlowExam.myAdvice()

                      myAdvice(f);

           }

           void myAdvice(First f) {

                      f.hello();

           }

}

 

[결과]

Hello …

Before Method ::public void

Onj.edu.aop7.First.hello()

Hello …

 

 

#ControllFlowPointcut, #스프링포인트컷, #스프링충고, #포인트컷, #스프링pointcut, #스프링AOP, #스프링advice, #SpringAOP, #스프링DI, #스프링IoC, #SpringDI, #SpringIoC, #자바스프링, #Spring동영상, #Spring강의, #스프링프레임워크, #스프링교육, #스프링학원, #스프링강좌, #스프링강의, #자바학원, #자바, #스프링동영상, #자바동영상, #스프링프레임워크교육, #스프링프레임워크강의, #스프링프레임워크학원 

, , , , , , , , , , , , , , , , , , , , , , , , ,

Comments