Afin de mettre en œuvre la journalisation en utilisant Spring AOP j'ai suivi ces étapes simples. Mais il semble que ça ne marche pas. Toute aide serait utilePointcut ne fonctionne pas avec Spring AOP
1) Créé MyLoggingAspect classe
import org.aspectj.lang.ProceedingJoinPoint;
public class MyLoggingAspect
{
public MyLoggingAspect() {
super();
System.out.println("Instantiated MyLoggingAspect");
}
public Object log(ProceedingJoinPoint call) throws Throwable
{
System.out.println("from logging aspect: entering method [" + call.toShortString()
+"] with param:"+call.getArgs()[0]);
Object point = call.proceed();
System.out.println("from logging aspect: exiting method [" + call.toShortString()
+ "with return as:" +point);
return point;
}
}
2) Création d'une classe (TixServiceImpl) où je veux vous connecter
public class TixServiceImpl implements TixService{
@Override
public void calculateSomething() {
String s = "did some calculation..";
System.out.println(s);
}
@Override
public String getTixName() {
return null;
}
}
3) Création d'un spring-aspectj.xml fichier
<beans...
<bean id="LoggingAspect" class = "MyLoggingAspect"/>
<aop:config>
<aop:aspect ref="LoggingAspect">
<aop:pointcut id="myCutLogging"
expression="execution(* TixService*.*(..))"/>
<aop:around pointcut-ref="myCutLogging" method="log"/>
</aop:aspect>
</aop:config>
</beans>
4) Création d'un client test simple (TixClient)
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
public class TixClient {
public static void main(String[] a){
ApplicationContext context = new FileSystemXmlApplicationContext("conf/spring-aspectj.xml");
TixService tix = new TixServiceImpl();
tix.calculateSomething();
String s = tix.getTixName();
System.out.println("End of the the client invocation!!");
}
}
5) Il me donne la suivante sortie
...
Instantiated MyLoggingAspect
did some calculation..
End of the the client invocation!!
Merci pour le conseil, cela a fonctionné. Ce serait bien si cela était mentionné dans les exemples/exemples/tutoriels disponibles en ligne. –
Heureux d'avoir aidé –