aspect注解(spring 中的和有什么区别)

本文目录
- spring 中的和有什么区别
- respect 和aspect 当“方面“讲有什么区别,要地道的解释.
- 如何在sping3.1 MVC中应用aspect注解之AOP
- @Aspect 注解不起作用,原因可能出现在什么方面
spring 中的和有什么区别
1、Advisor:充当Advice和Pointcut的适配器,类似使用Aspect的@Aspect注解的类(前一章节所述)。一般有advice和pointcut属性。
祖先接口为org.springframework.aop.Advisor,应用中可直接使用org.springframework.aop.support.DefaultPointcutAdvisor
2、Advice:用于定义拦截行为,祖先接口为org.aopalliance.aop.Advice,该接口只是标识接口,应用中可直接实现BeforeAdvice ,ThrowsAdvice,MethodInterceptor ,AfterReturningAdvice ,IntroductionInterceptor 等子接口
3、Pointcut:用于定义拦截目标集合,祖先接口为org.springframework.aop.Pointcut!
respect 和aspect 当“方面“讲有什么区别,要地道的解释.
aspect作“方面”解时,英文解释是“particular
part
or
feature
of
sth
being
considered”
respect作“方面;着眼点”,英文解释是“particular
aspect
or
detail”
两词意思有相同的部分,有时可以互用,但respect比aspect似乎更具体,在某些小方面上常用respect
aspect
是指事态
想法
计划等的某个方面
比如说
the
training
program
covers
every
aspect
of
the
job.
训练计划的范围包括了这个工作的各各方面
repect
是指某一细节的方面
比如说
in
many
respects
pf
the
new
version
is
less
good
than
the
old
one.
从许多方面来看
新的版本并不比旧的强.
如何在sping3.1 MVC中应用aspect注解之AOP
最近在项目有一个操作时间监控功能
项目采用的是 spring3.1 mvc -control注解
为了对所有的操作进行执行时间监控,编写了一个AOP
配置mvc aop的时候,刚开始按照普通的aspect注解的方式配置,无法生效。
后面查了相关的资料,有的说@control不支持AOP ,有的说支持,但笔者最后还是成功的找到了
相关的配置方法,因为笔者喜欢Aspect的注解风格。所以笔者只提供Aspect风格的相关配置。相关jar网上搜下。笔者只讲mvc 切面生效的配置。
前提条件MVC配置成功。
编写AOP类
package com.wx.aop.timer;
import org.apache.log4j.Logger;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;
@Component
@Aspect
public class Timer {
private Logger logger =Logger.getLogger(getClass());
//可以尝试下这两种注解
// @Around(“execution(* org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(..))“)
@Around(“@annotation(org.springframework.web.bind.annotation.RequestMapping)“)
public Object logTimer(ProceedingJoinPoint thisJoinPoint) throws Throwable {
String clazzName = thisJoinPoint.getTarget().getClass().getName();
String methodName = thisJoinPoint.getSignature().getName();
// 计时并调用目标函数
long start = System.currentTimeMillis();
Object result = thisJoinPoint.proceed();
long time = System.currentTimeMillis() - start;
// 输出计时信息
logger.info(“操作计时:“ + time + “ms 类名: “ + clazzName+ “ 方法名:“ + methodName + “()“);
return result;
}
}
spring-servlet配置文件加入下面配置语句:
《aop:aspectj-autoproxy proxy-target-class=“true“ /》 《!-- aspect注解生效--》
《!-- aop切面 --》
《bean id=“timer“ class=“com.wx.aop.timer.Timer“ /》
笔者mvc配置文件为spring-servlet.xml.整个配置文件如下:
《?xml version=“1.0“ encoding=“UTF-8“?》
《beans xmlns=“祝你愉快,满意请采纳哦
@Aspect 注解不起作用,原因可能出现在什么方面
如何在sping3.1 MVC中应用aspect注解之AOP 编译连接应用、注册COM服务程序 对ATL工程的编译连接过程包括下面的几个步骤: 使用MIDL编译工程的IDL文件,形成接口定义的头文件和用于调度(Marshalling)的代码; 编译工程的.cpp文件形成目标文件

更多文章:
another time(another time和other time的区别)
2026年10月11日 05:00









