@Before、@After注解的方法都不执行
@Aspect @Component public class AspectConfig { @Pointcut("args(Integer) && within(com.imooc.miaosha.controller.*)") public void matchArgs() {} @Before("matchArgs()") public void before_1() { System.out.println("####before1"); } @After("matchArgs()") public void after_1() { System.out.println("####after1"); } }
package com.imooc.miaosha.controller; @Controller @RequestMapping("/demo") public class SampleController { @RequestMapping("/hello") @ResponseBody public Result<String> home() { System.out.println("hello"); printInteger(100); return Result.success("Hello,world"); } private void printInteger(Integer i) { System.out.println("this is "+i); } }
运行结果:访问http://localhost:8080/demo/hello,正常运行,没有报异常,但是AspectConfig类中的before_1、after_1方法都没有执行