81,092
社区成员
发帖
与我相关
我的任务
分享
@Documented
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface LogsDescribe {
/**
* 接口名称
* @return
*/
String value() default "";
}
Aspect
@Aspect
@Component
public class LogsDescribeAspect {
private static final Logger logger = LoggerFactory.getLogger(LogsDescribeAspect.class);
@Resource(name="operationLogService")
private OperationLogService operationLogService;
@Pointcut("@annotation(com.huangbl.blog.config.LogsDescribe)")
private void cut() {
}
@Before("cut()")
public void before(JoinPoint joinPoint) {
logger.info("LogsDescribe...before");
}
@After("cut()")
public void after(JoinPoint joinPoint) {
logger.info("LogsDescribe...after");
}
}
service中使用注解的方法和你的一样,代码我就不发了
最后就是Aspect自动代理,在spring配置文件中加上(在spring boot中只需要在服务启动类上加上@EnableAspectJAutoProxy)
<aop:aspectj-autoproxy proxy-target-class="true" />
<aop:aspectj-autoproxy proxy-target-class="true" />