一个Hello引发的Spring AOP 实战用法解析
作者:互联网
实战用法:
- 1:接口方法
package com.xxx.xxx.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping(value = "/api/open")
public class OpenController {
@RequestMapping(value = "/hello", method = { RequestMethod.GET })
public JsonResult hello() {
return new JsonResult("welcome to HOME");
}
}
- 2:定义切面
package com.xxx.xxx.aspect;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.an
标签:xxx,Spring,AOP,springframework,annotation,org,import,Hello,aspectj 来源: https://blog.csdn.net/qq_38634142/article/details/121949075