AOP 의 개요,
<!-- Enables the Spring MVC @Controller programming model -->
<annotation-driven />
<!-- aop의 설정을 통한 자동적인 Proxy 객체 설정 -->
<aop:aspectj-autoproxy></aop:aspectj-autoproxy>
<!-- 트랜잭션 처리 -->
<tx:annotation-driven/>
<!-- AOP 드라이브 -->
<!-- https://mvnrepository.com/artifact/org.aspectj/aspectjweaver -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.6.11</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.6.8</version>
</dependency>
@Component //스프링에서 관리하는 bean
@Aspect //aop bean
public class LogAdvice {
//로그 수집 객체
private static final Logger logger =LoggerFactory.getLogger(LogAdvice.class);
//ProceedingJoinPoint 클래스는 around 에서 만 가능
@Around("execution( * com.macaronics.www.member.controller..*Controller.*(..))"
+ " or execution( * com.macaronics.www.member.model.dao.board..*Impl.*(..))"
+ " or execution( * com.macaronics.www.member.service.board..*Impl.*(..))")
public Object logPrint(ProceedingJoinPoint joinPoint) throws Throwable{
long start =System.currentTimeMillis();
Object result =joinPoint.proceed();
String type =joinPoint.getSignature().getDeclaringTypeName();
String name="";
if(type.indexOf("Controller") > -1){
name ="Controller \t : ";
}else if(type.indexOf("Service") > -1){
name ="ServiceImpl \t: ";
}else if(type.indexOf("DAO") > -1){
name ="DAO \t: ";
}
//클래스 + 매소드 이름
logger.info( "*******" + name+type+"."+joinPoint.getSignature().getName() +"()");
//파라미터 값
logger.info(Arrays.toString(joinPoint.getArgs()));
long end =System.currentTimeMillis();
long time =end-start;
logger.info(result +" 실행시간 :" + time);
return joinPoint.proceed();
}
}
댓글 ( 4)
댓글 남기기