spring boot 实现 AOP
切面配置
@Component @Aspect public class HelloAspect { @Pointcut("execution(* com.educationtek.daoxue.controller.*.*(..))") public void pointCut() { } @Before("pointCut()") public void begin(){ System.out.println("开启事务"); } @After("pointCut()") public void close(){ System.out.println("关闭事务"); } }
业务逻辑
@RestController
@RequestMapping(value = "/api/hello")
public class HelloController {
@GetMapping("/aop")
public String printString(){
System.out.println("hello,Aop!");
return "hello,Aop";
}
}
程序输出