开发者

Spring AOP within pointcut

package com.vanilla.daoService;

    @Repository("da开发者_StackOverflow中文版oService")
    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?


You probably want this:

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

BlService+ means BlService and all subclasses / implementing classes.


You should use the below pointcut

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


Try to use:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜