切入点内的 Spring AOP
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
}
}
我的业务逻辑类:
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);
}
}
现在我想测量每个业务逻辑函数 (daoservice.*) 中执行的所有方法的执行情况,
我创建了我的 Aspect 类,
@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;
}
}
不幸的是,什么也没发生。我认为我的 @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
}
}
my Business Logic class:
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);
}
}
Now I would like to measure execution of all methods executed within each of Business logic functions (daoservice.*)
I create my Aspect classes
@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;
}
}
Unfortunately, nothing happened. I think my @PointCut
definition is incorrect how can I do it correctly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可能想要这样:
BlService+
表示 BlService 和所有子类/实现类。You probably want this:
BlService+
means BlService and all subclasses / implementing classes.您应该使用下面的切入点
You should use the below pointcut
尝试使用:
Try to use: