Spring AOP innerhalb pointcut
package com.vanilla.daoService;
@Repository("daoService")
public class DaoServiceImpl implements DaoService {
@Override
public String addStudent(Student student) {
//saving new user
}
@Override
public String updateStudent(Student student) {
//update new user
}
@Override
public String getStudent(String id) {
//update new user
}
}
meine Business-Logik-Klasse:
package com.vanilla.blService;
@Service("blService")
public class BlServiceImpl implements BlService {
@Autowired
DaoService daoService;
@Override
public void updateStudent(String id){
Student s = daoService.getStudent(id);
set.setAddress(address);
daoService.updateStudent(s);
}
}
Nun würde ich gerne Messen, Ausführung aller Methoden ausgeführt, die in jedem von Business-Logik-Funktionen (daoservice.*)
Erstelle ich mir ein Aspekt-Klassen
@Aspect
public class BlServiceProfiler {
@Pointcut("within(com.vanilla.blService.BlService.*)")
public void businessLogicMethods(){}
@Around("businessLogicMethods()")
public Object profile(ProceedingJoinPoint pjp) throws Throwable {
long start = System.currentTimeMillis();
System.out.println("Going to call the method " + pjp.toShortString());
Object output = pjp.proceed();
System.out.println("Method execution completed.");
long elapsedTime = System.currentTimeMillis() - start;
System.out.println(pjp.toShortString()+" execution time: " + elapsedTime + " milliseconds.");
return output;
}
}
Passierte leider nichts. Ich denke, dass meine @PointCut
definition ist falsch, wie kann ich es richtig machen?
- Registrieren Sie den Aspekt mit dem Frühling? (Nur Kontrolle,...)
- ja, habe ich 🙂
Du musst angemeldet sein, um einen Kommentar abzugeben.
Möchten Sie wahrscheinlich diese:
BlService+
bedeutet BlService und allen Unterklassen /Implementierung von Klassen.within(com.vanilla.daoService.DaoService+)
. Deine Frage sagt, du willst pointcut DAOs aber dein code-Beispiel bedeutet, dass Sie versuchen pointcut-Dienste, die ein bisschen verwirrend.Sollten Sie die unten pointcut
Versuchen, Sie zu nutzen:
call
ist nicht unterstützt in der @AspectJ in Spring. Versuchenexecution
als in festen code.