微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

切入点内的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定义不正确,我该如何正确执行?

最佳答案
您可能想要这样:

@pointcut("within(com.vanilla.blService.BlService+)")
public void businessLogicmethods(){}

BlService表示BlService及其所有子类/实现类.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐