Skip to content

Commit 67811d4

Browse files
AOP
1 parent d910bed commit 67811d4

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.naturalprogrammer.spring.tutorial.aop;
2+
3+
import org.apache.commons.logging.Log;
4+
import org.apache.commons.logging.LogFactory;
5+
import org.aspectj.lang.ProceedingJoinPoint;
6+
import org.aspectj.lang.annotation.Around;
7+
import org.aspectj.lang.annotation.Aspect;
8+
import org.springframework.stereotype.Component;
9+
10+
@Component
11+
@Aspect
12+
public class RequestMonitor {
13+
14+
private static final Log log = LogFactory.getLog(RequestMonitor.class);
15+
16+
@Around("within(com.naturalprogrammer.spring.tutorial.controllers.*)")
17+
public Object wrap(ProceedingJoinPoint pjp) throws Throwable {
18+
19+
log.info("Before handler '"
20+
+ pjp.getSignature().getName() + "'. Thread "
21+
+ Thread.currentThread().getName()); // toString gives more info
22+
23+
Object retVal = pjp.proceed();
24+
25+
log.info("Handler '"
26+
+ pjp.getSignature().getName()
27+
+ "' execution successful");
28+
29+
return retVal;
30+
}
31+
}

0 commit comments

Comments
 (0)