应用中可以使用AOP的特性来记录各层(采用分层设计的情况下)的日志:
1,实现MethodInterceptor
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class ServiceMethodInterceptor implements MethodInterceptor{
private final Log LOG = LogFactory.getLog(ServiceMethodInterceptor.class);
@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
Object object = null;
LOG.info("before service....");
object = invocation.proceed();
LOG.info("after service....");
return object;
}
}
2,配置MethodInterceptor
<bean id="serviceMethodInterceptor" class="*.ServiceMethodInterceptor"/>
.........