I have written the class "LogAspect.java":
package fi.wmdata.hr.apps.recruiting.common.logging;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
@Aspect
public class LogAspect {
private static Log log = null;
@Around("fi.wmdata.hr.apps.recruiting.common.loggi ng.LogPointcut.Around()")
public Object log(ProceedingJoinPoint call) throws Throwable
{
log = LogFactory.getLog(getClass());
System.out.println(call.toLongString());
log.info("************** Before Executing : "+ call.getSignature().toLongString()+" with parameters: ");
int paramLength = call.getArgs().length;
for(int i=0; i<paramLength; i++){
log.info(call.getArgs()[i]);
}
Object point = call.proceed();
log.info("************** After method Exection: "+ call.getSignature().toLongString()+" **************");
return point;
}
}
and "LogPointcut" pointcut class:
package fi.wmdata.hr.apps.recruiting.common.logging;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
@Aspect
public class LogPointcut {
@Pointcut("execution(public * fi.wmdata.hr.apps.recruiting.um.*.*.*(..)) ||"+
"execution(public * fi.wmdata.hr.apps.recruiting.ln.*.*.*(..))"
)
public void Around(){
}
}
and the configuration file is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<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/beans
http://www.springframework.org/schem...ring-beans.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd">
<!-- Logging entries start -->
<aop:aspectj-autoproxy/>
<aop:config>
<aop:aspect ref="logAspect" >
<aopointcut id="around"
expression="fi.wmdata.hr.apps.recruiting.common.lo gging.LogPointcut.Around()" />
<aop:around pointcut-ref="around"
method="log" />
</aop:aspect>
</aop:config>
<bean id="logAspect" class="fi.wmdata.hr.apps.recruiting.common.logging .LogAspect" />
<bean id="logPointcut" class="fi.wmdata.hr.apps.recruiting.common.logging .LogPointcut" />
<!-- Logging entries end -->
</beans>
Problem is i am getting duplicate messages in the logging.
Please give me some advice.
I went through the similar one's, but i was not able to understand correctly.
In one of the posts it is explained that this will happen when:
"logging of the Interceptor is done instead of logging the class or package defined as a pointcut".
I am a begineer in Spring so please even if it is a simple one also reply.
Thanking in advance
Mahammad Ghouse


ointcut id="around"
Reply With Quote