-
spring 中的<aop:advisor>和<aop:aspect>有什么区别?不同之处在那里,请大牛们帮小弟解一下疑惑5
<tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="save*" propagation="REQUIRED"/> <tx:method name="delete*" propagation="REQUIRED"/> <tx:method name="get*" read-only="true"/> <tx:method name="find*" read-only="true"/> </tx:attributes> </tx:advice> <bean id="dataAccessThrowsAdvice" class="com.XXX.XXX.aop.exception.XXX" /> <bean id="serviceThrowsAdvice" class="com.XXXXXX.aop.exception.XXX" /> <bean id="actionThrowsAdvice" class="com.XXX.XXXaop.exception.XXX" /> <aop:aspectj-autoproxy/> <aop:config proxy-target-class="true"> <!-- 切面事务归txAdvice处理 --> <aop:advisor advice-ref="txAdvice" pointcut="execution(* com.XXX..*.*Dao.*(..))" /> <aop:advisor advice-ref="txAdvice" pointcut="execution(* com.XXX..*.*Manager.*(..))" /> <aop:advisor advice-ref="txAdvice" pointcut="execution(* com.XXX..*.*Action.*(..))" /> <aop:advisor advice-ref="dataAccessThrowsAdvice" pointcut="execution(* com.XXX..*.*Dao.*(..))"/> <aop:advisor advice-ref="serviceThrowsAdvice" pointcut="execution(* com.XXX..*.*Dao.*(..))" /> <aop:advisor advice-ref="actionThrowsAdvice" pointcut="execution(* com.XXX..*.*Action.*(..))" /> </aop:config>
spring 中的<aop:advisor>和<aop:aspect>有什么区别?不同之处在那里,请大牛们帮小弟解一下疑惑配置文件如上
然后我写了一个类:如下:
import org.springframework.aop.MethodBeforeAdvice; import org.springframework.aop.ThrowsAdvice; public class BaseBeforeAdvice implements MethodBeforeAdvice{ @Override public void before(Method arg0, Object[] arg1, Object arg2) throws Throwable { System.out.println("******************"); System.out.println(arg0.getName()); System.out.println("******************"); }
小弟不明白这个方法和这种有什么区别:
@Aspect public class wqAdvice { @Pointcut("execution (* com.XX.*.XX.*(..))") private void myXXCut(){} @Before("myXXCut()") public void doBefore(){ System.out.println("before"); } @AfterReturning(pointcut="myXXCut()",returning="result") public void doAfter(String result){ System.out.println("atfer"+result); } @AfterThrowing(pointcut=" myXXCut()",throwing="e") public void doThrowing(Exception e){ System.out.println("Exception"+e.getMessage()); } }
疑惑颇重,希望大牛们指点小弟一下
2011年8月10日 16:52
2个答案 按时间排序 按投票排序
-
采纳的答案
引用
spring 中的<aop:advisor>和<aop:aspect>有什么区别?
在AOP中有几个概念:
— 方面(Aspect):一个关注点的模块化,这个关注点实现可能另外横切多个对象。事务管理是J2EE应用中一个很好的横切关注点例子。方面用Spring的Advisor或拦截器实现。
— 连接点(Joinpoint):程序执行过程中明确的点,如方法的调用或特定的异常被抛出。
— 通知(Advice):在特定的连接点,AOP框架执行的动作。各种类型的通知包括“around”、“before”和“throws”通知。
— 切入点(Pointcut):指定一个通知将被引发的一系列连接点的集合。AOP框架必须允许开发者指定切入点,例如,使用正则表达式。
所以“<aop:aspect>”实际上是定义横切逻辑,就是在连接点上做什么,“<aop:advisor>”则定义了在哪些连接点应用什么<aop:aspect>。Spring这样做的好处就是可以让多个横切逻辑(即<aop:aspect>定义的)多次使用,提供可重用性。
你后面的两个类实际上就是实现横切逻辑的不同方式,一种需要实现特定接口,一种以POJO + Annotation , 在功能上没有太大差别,只是方式不同。2011年8月10日 17:23
-
1、Adivisor是一种特殊的Aspect,Advisor代表spring中的Aspect
2、区别:advisor只持有一个Pointcut和一个advice,而aspect可以多个pointcut和多个advice2011年8月10日 17:59
相关推荐
基于XML的声明式AspectJ是指通过XML文件来定义切面、切入点及通知,所有的切面、切入点和通知都必须定义在<aop:config>元素内。 基于XML的声明式AspectJ <aop:config>元素及其子元素如下: 小提示:图中灰色部分标注...
配置可以通过xml文件来进行,大概有四种方式: 1. 配置ProxyFactoryBean,显式地设置advisors, advice, target等(基于代理的AOP ) 2. 配置AutoProxyCreator,这种方式下,还是如以前一样使用定义的bean,但是从...
SPRING:aspect和advisor区别
通过接口实现增强处理是较低版本Spring AOP的做法,如果在一个使用低版本Spring AOP开发的项目上进行升级,可以考虑使用<aop:advisor>复用已经存在的增强类;如果项目采用JDK 5.0以上版本,可以考虑使用@AspectJ注解...
x.y.service.ddl.DefaultDdlManager.*(..))" /> <aop:advisor pointcut-ref="defaultServiceOperation" advice-ref="defaultTxAdvice" /> <aop:advisor pointcut-ref="noTxServiceOperation" advice-ref=...
<aop:aspect ref="loggingAspect"> <!-- 配置通知 --> <aop:before method="beforeMethod" pointcut-ref="pointcut1"/> <aop:around method="aroundMethod" pointcut-ref="pointcut2"/> </aop:aspect> ...
<aop:aspect id="aspect" ref="logIntercepter"> 引入具体的AOP操作类 <aop:pointcut expression="execution(* com.spring.service..*(..))" id="pointCut"/>声明一个切入点,注意execution表达式的写法 <aop:before ...
赠送jar包:spring-aop-5.0.10.RELEASE.jar; 赠送原API文档:spring-aop-5.0.10.RELEASE-javadoc.jar; 赠送源代码:spring-aop-5.0.10....人性化翻译,文档中的代码和结构保持不变,注释和说明精准翻译,请放心使用。
Spring2.5开发 如果我们用到了AOP的话 一定需要aspectjrt.jar + aspectjweaver.jar 两个jar文件 这里面提供了 导入这两个就可以进行AOP开发了
<aop:advisor pointcut-ref="allManagerMethodPdm" advice-ref="txAdvicePdm"/> </aop:config> <!-- ibatis插件 --> <bean id="sqlMapClient" class="org.springframework.orm.ibatis....
<aop:advisor pointcut-ref="allServiceMethod" advice-ref="txAdvice"/> </aop:config> <!-- 新闻类型 --> <bean id="newsclassAction" class="com.cstp.web.NewsclassAction"> <property name=...
<!--配置连接池--> <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"> <property name="driverClassName" value=... <aop:advisor advice-ref="advice" pointcut-ref=
<br>Before Advice <br>After Advice <br>Around Advice <br>Throw Advice <br>Pointcut、Advisor <br>Pointcut 定义了 Advice 的应用时机,在 Spring 中,使用 PointcutAdvisor 将 Pointcut 与 Advice 结合成为一个...
Spring2.5和Hibernate3集成 采用声明式事务 1.声明式事务的配置 * 配置sessionFactory * 配置事务管理器 * 配置事务的传播特性 * 配置哪些类哪些方法使用事务 2.编写业务逻辑方法 * 继承...
<?xml version="1.0" encoding="UTF-8"?> <!-- - Application context definition for JPetStore's business layer. - Contains bean references to the transaction manager and to the DAOs in - ...
第三种实现方法—通过注解来实现 签名 注解实现aop <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" ... <aop:aspectj-autoproxy/> </beans>
Spring AOP 拦截器 Advisor Spring AOP 拦截器 Advisor
spring-aop-1.1.1.jar spring-aop-1.2.6.jar spring-aop-1.2.9.jar spring-aop-2.0.2.jar spring-aop-2.0.6.jar spring-aop-2.0.7.jar spring-aop-2.0.8.jar spring-aop-2.0.jar spring-aop-2.5.1.jar spring-aop-...
<aop:advisor pointcut-ref="serviceOperation" advice-ref="txAdvice"/> </aop:config> <!-- 通知配置 --> <tx:advice id="txAdvice" transaction-manager="myJtaManager"> <tx:attributes> <tx:method name...
spring中AOP中标签加载通知,spring中AOP中标签加载通知spring中AOP中标签加载通知spring中AOP中标签加载通知,spring中AOP中标签加载通知