Hi,
currently I'm trying to use Spring's AOP for logging. I've written some simple test beans and a LoggingInterceptor. I configured everything in in my beans-config.xml. Then I've created the ApplicationContext and called an abitrary method in one of my test beans. The method is called successfully, but I can't see any logging in my console. It seems that my logging advice is completly ignored.
Here my LoggingInterceptor:
My Spring configuration is as follows:Code:import java.lang.reflect.Method; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.aop.AfterReturningAdvice; import org.springframework.aop.MethodBeforeAdvice; import org.springframework.aop.ThrowsAdvice; public class LoggingInterceptor implements MethodBeforeAdvice, AfterReturningAdvice, ThrowsAdvice { private static Log log = null; public LoggingInterceptor() {} public void before(Method arg0, Object[] arg1, Object arg2) throws Throwable { System.out.println("Entering method: " + arg0.getName()); log = LogFactory.getLog(arg2.getClass()); log.info("Entering method: " + arg0.getName()); } public void afterReturning(Object arg0, Method arg1, Object[] arg2, Object arg3) throws Throwable { log = LogFactory.getLog(arg3.getClass()); log.info("Leaving method: " + arg1.getName()); } public void afterThrowing(Method m, Object[] args, Object target, Throwable ex) { log = LogFactory.getLog(target.getClass()); log.info("Exception in method: " + m.getName() + " Exception is: " + ex.getMessage()); } }
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<bean id="loggingInterceptor" class="temp.LoggingInterceptor" />
<bean id="knightWithLogging"
class="org.springframework.aop.framework.ProxyFact oryBean">
<property name="proxyInterfaces">
<value>temp.Knight</value>
</property>
<property name="interceptorNames">
<list>
<value>loggingInterceptor</value>
</list>
</property>
<property name="target" ref="knight" />
</bean>
<bean id="quest" class="temp.HolyGrailQuest" />
<bean id="knight" class="temp.KnightImpl">
<constructor-arg>
<value>Belvidere</value>
</constructor-arg>
<property name="quest">
<ref bean="quest" />
</property>
</bean>
</beans>
Any ideas what the problem could be?
Thx a lot.


Reply With Quote
