웹 & 프레임워크

Spring AOP, LogAspect이용법

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

AOP이용하려면 먼저 Namespace에 등록하자

AspectJ 도 알면 좋다

 

 

<?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:p="http://www.springframework.org/schema/p"

                           xmlns:aop="http://www.springframework.org/schema/aop"

                           xsi:schemaLocation="http://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop-3.2.xsd

                                                     http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.2.xsd">

 

 

 

<!-- 핵심로직 빈등록 -->

<bean id="greeting" class="com.xml.GreetingServiceImpl"

                           p:outputter-ref="outputter"/>

<bean id="outputter" class="com.xml.OutputServiceImplConsole"/>

 

<!-- 공통로직 빈등록 -->

<bean id="logAspect" class="com.gorakgarak.xml.LogAspect"/>

 

<!-- * say*(..) 의미하는 바는?

접근지정자 - 메소드의 선언부에서 쓰는 거런거 public 같은거

[]로써있는거 생략가능 , 클래스타입패턴 생략하면 모든놈들이 

                          

                           execution( [접근지정자리턴타입 [클래스타입패턴]

                            메소드이름패턴(매개변수타입패턴) [throws 예외]                    )

 

 그래서 * say*(..)접근지정자는 생략 (public으로 되어있을테니 생략)

 리턴타입은 *인데 아무것도 상관이없다는거

 클래스타입은 뺐으니 모오든 놈들 고고, say 시작하는 놈들 

, (..)매개변수는 한개와도되고 뭐도되고 다와도됨 -->

<aop:config>

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

                           <aop:aspect ref="logAspect">

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

                           </aop:aspect>

</aop:config>

 

</beans>