加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

切入点内的Spring AOP

发布时间:2020-12-15 01:19:49 所属栏目:大数据 来源:网络整理
导读: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)

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及其所有子类/实现类.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读