I am trying to log the start, end and time taken to execute each method. I have the following in applicationContext.xml
MyInterceptor code looks like thisCode:<bean id="managerProxyCreator" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator"> <property name="beanNames"><value>*Image*</value></property> <property name="proxyTargetClass"><value>true</value></property> <property name="interceptorNames"> <list> <value>myInterceptor</value> <value>loggingInterceptor</value> </list> </property> </bean> <bean id="myInterceptor" class="com.company.interceptor.MyInterceptor" /> <bean id="loggingInterceptor" class="org.springframework.aop.interceptor.SimpleTraceInterceptor"/> <bean id="hibImage" class="com.company.grayline.image.HibImageImpl"> <property name="sessionFactory"><ref local="sessionFactory"/></property> </bean>
it does not log anything. Can anyone point out what is that I am doing wrong.Code:import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; public class MyInterceptor implements MethodInterceptor { private final Log logger = LogFactory.getLog("MAIN"); public Object invoke(MethodInvocation methodInvocation) throws Throwable { if(logger.isInfoEnabled()){ logger.info("********Beginning method: " + methodInvocation.getMethod().getDeclaringClass() + "::" + methodInvocation.getMethod().getName()); } long startTime = System.currentTimeMillis(); try { Object retVal = methodInvocation.proceed(); return retVal; } finally { if(logger.isInfoEnabled()){ logger.info(">>>>>>>>>>>>>Method invocation time: " + (System.currentTimeMillis() - startTime) + " msecs."); logger.info("##########Ending method: " + methodInvocation.getMethod().getDeclaringClass() + "::" + methodInvocation.getMethod().getName()); } } } }
Thanks


Reply With Quote