웹 & 프레임워크

Spring AOP 이용법, 매개변수 하나

늘근이 2014. 6. 27. 14:49

<aop:config>

<!-- <aop:pointcut expression="execution(* say*(..))" id="sayPointcut"/> -->

<aop:pointcut expression="execution(* say*(java.lang.String))" id="sayPointcut"/>

                  <aop:aspect ref="logAspect">

                  <aop:before method="beforeLogging" pointcut-ref="sayPointcut"/>

                  </aop:aspect>

</aop:config>

 

 

</beans>

 

                  public void beforeLogging(JoinPoint joinPoint){

                                   System.out.println(joinPoint.getSignature().getName() + "메소드 호출  :" +

                                                                       joinPoint.getArgs()[0]);

                  }

 

결과

sayGoodBye메소드 호출 전 :윤시윤

GoodBye윤시윤




<aop:config>

<!-- <aop:pointcut expression="execution(* say*(..))" id="sayPointcut"/> -->

<!-- xml아래 하위타입다 나오셈! com... 이렇게도 쓸수있따 -->

<aop:pointcut expression="execution(* com.gorakgarak.sample1.xml..*(java.lang.String))" id="sayPointcut"/>

                  <aop:aspect ref="logAspect">

                  <aop:before method="beforeLogging" pointcut-ref="sayPointcut"/>

                  </aop:aspect>

 

</aop:config>

//밑에처럼 쓰면 output을 비롯해 막 튀어나올수도 있다!