웹 & 프레임워크

Spring 에노테이션 기반 AOP

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

//공통모듈임을 나타내주어야함순서는 상관없음! aspect 콤포논트의 확장된 버전이면

//상관없는데얘는 확장한 버전이 아니라 두개를 같이 써줘야함

@Aspect

@Component

public class LogAspect {

}

 

                  @Before(value="execution(* com.gorakgarak..*(java.lang.String))")

                  public void beforeLogging(JoinPoint joinPoint){

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

                                                                       joinPoint.getArgs()[0]);

                   }

 

 

둘다 해줘야함

 

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

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

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

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

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

                                   http://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-3.2.xsd">

 

<context:component-scan base-package="com.gorakgarak.sample2.annotation"></context:component-scan>

<aop:aspectj-autoproxy/>

 

</beans>