일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
- resource
- maVen
- vscode
- GIT
- profile
- Mac
- 네트워크
- VirtualBox
- Windows 10
- web.xml
- IntelliJ
- plugin
- import
- 줄바꿈 문자
- Windows
- 단축키
- xargs
- Eclipse
- Quartz
- ssh
- JavaScript
- tomcat
- lsof
- port
- netsh
- context
- find
- Source
- bash
- grep
- Today
- Total
develog
Spring AOP Aspect 설정 본문
<bean id="LogAspect" class="com.my.LogAspect" />
<aop:config proxy-target-class="true">
<aop:aspect ref="LogAspect">
<aop:pointcut id="exceptionThrowing" expression="execution(* *..*Service.*(..))" />
<aop:after-throwing pointcut-ref="exceptionThrowing" method="exceptionThrowing" throwing="ex" arg-names="ex" />
</aop:aspect>
</aop:config>
-----------------------------------------------------------------------------------------------------------------
package com.my;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.Signature;
public class LogAspect {
private final Log logger = LogFactory.getLog(getClass());
public void before(JoinPoint joinPoint) {
if (logger.isInfoEnabled()) {
logger.info("[Aspect] before() => " + getFullName(joinPoint));
logger.info("[Aspect] args : " + getArgs(joinPoint));
}
}
public void afterReturning(JoinPoint joinPoint, Object ret) {
if (logger.isInfoEnabled()) {
logger.info("[Aspect] afterReturning() => " + getFullName(joinPoint));
logger.info("[Aspect] ret => " + ret);
}
}
public void afterThrowing(JoinPoint joinPoint, Exception ex) {
if (logger.isErrorEnabled()) {
logger.error("[Aspect] afterThrowing() => " + getFullName(joinPoint));
logger.error("[Aspect] ex => " + ex, ex);
}
}
public void exceptionThrowing(JoinPoint joinPoint, Exception ex) {
if (logger.isErrorEnabled()) {
logger.error("[Aspect] exceptionThrowing() => " + getFullName(joinPoint));
logger.error("[Aspect] ex => " + ex, ex);
}
}
private String getArgs(JoinPoint joinPoint) {
StringBuffer sb = new StringBuffer();
Object[] args = joinPoint.getArgs();
for (int i = 0; i < args.length; i++) {
sb.append("\n" + i + ". " + args[i]);
}
return sb.toString();
}
private String getFullName(JoinPoint joinPoint) {
Signature signature = joinPoint.getSignature();
StringBuffer sb = new StringBuffer();
sb.append(signature.getDeclaringTypeName());
sb.append(".");
sb.append(signature.getName());
return sb.toString();
}
}
'Dev > Spring' 카테고리의 다른 글
Spring AOP Pointcut expression (0) | 2013.12.11 |
---|---|
Spring AOP 설정 (0) | 2013.12.11 |
Spring AOP LoggingAdvice (0) | 2013.11.29 |
REQUIRED, REQUIRES_NEW (0) | 2013.07.18 |
spring jar download (0) | 2013.07.09 |