切入点内的Spring AOP

时间:2011-07-29 12:09:26

标签: spring java-ee aspectj 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
             }
    }

我的Business Logic课程:

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定义不正确我怎么能正确地做到这一点?

3 个答案:

答案 0 :(得分:2)

你可能想要这个:

@Pointcut("within(com.vanilla.blService.BlService+)")
public void businessLogicMethods(){}

BlService+表示BlService和所有子类/实现类。

答案 1 :(得分:1)

您应该使用以下切入点

@Pointcut("execution(* com.vanilla.blService.BlService.*(..))")

答案 2 :(得分:0)

尝试使用:

within(com.vanilla.blService.BlService) && execution(public * com.vanilla.daoService..*.*(..))