プロキシを手動で作成しないでください。Spring AOPを使用して Logging Proxy を作成してください。
簡単なアスペクトを作成します。
@Aspect
public class LoggingAspect{
private static final Logger log = Logger.getLogger(LoggingAspect.class);
@Pointcut("execution(* *.*(..))")
public void methodExecution(){
}
@Before("methodExecution()")
public void logBeforeMethod(final JoinPoint joinPoint){
log.trace("Entering method " + joinPoint.getSignature() + " with args "
+ Arrays.toString(joinPoint.getArgs()));
}
}
次に、Spring でアスペクトを配線します。
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean class="aspects.LoggingAspect" />
<aop:aspectj-autoproxy />
</beans>
これで、すべての Spring Bean がプロキシになり、それらのすべてのメソッド実行 (少なくともインターフェースによってサポートされているもの) がログに記録されます。
ところで:アスペクトのトレースは
、Ramnivas Laddad によるAspectJ in Actionの無料の第 10 章で説明されています。