- 浏览: 73571 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
george.gu:
lqjacklee 写道怎么解决。。 First: Conf ...
Bad version number in .class file -
lqjacklee:
怎么解决。。
Bad version number in .class file -
flyqantas:
would you pleade left more mate ...
UML Extension
I had heared about AOP almost 7 years but only used it in two projects. 7 Years, I still only know few about AOP, if i were not involved in that two projects, i would still know that few.
The fact is always like that:
- Hear about it.
- Know how to use it.
- Use it in project
- Know what's problem it solved and try to enhance it.
First story: Why there is no "before" or "after" method execution Advice?
Normally for a AOP, we can say there are point-cuts or events:
- Befroe execution
- Before return
- Exception catch and processing in case exception raised
First time, I use AOP with EJB3. Thanks to annotation @Interceptor and @AroudInvoke, i can define AOP interceptors easily. But for a long time during, I was always wondering:
- Why there is only "around " invokea method, but no "before" or "after" invoke methods?
Second story: Exception used as logical condition had been intercepted by prior interceptor
- Catch Exception from point-cut and retry execution in case there is exception.
- If max retry number catched, marks Transaction to be "Rollback Only".
<tx:advice id="tx-advice" transaction-manager="myTransactionManager"> <tx:attributes> <tx:method name="*" propagation="REQUIRED" rollback-for="java.lang.Exception"/> </tx:attributes> </tx:advice>
<bean id="myTransactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory"> <ref bean="mySessionFactory"/> </property> </bean>
<bean id="TransactionRetryInterceptor" class="com.MyTransactionRetryInterceptor"/> |
Here is the shanpshot for MyTransactionRetryInterceptor:
public Object invoke(MethodInvocation invocation) throws Throwable { int retryCount = 0; logger.info("TRANSACTION BEGIN"); while (true) { try { ReflectiveMethodInvocation inv = (ReflectiveMethodInvocation) invocation; MethodInvocation anotherInvocation = inv.invocableClone(); Object obj = anotherInvocation.proceed(); logger.info("TRANSACTION END: OK"); return obj; } catch (Exception ex) { // If reached maximum number of retries then just rethrow this exception immediately. if (++retryCount > maxRetryCount) { logger.error ("TRANSACTION FAIL: max retries reached:", ex); throw ex; }
//TODO...check if the transaction need to be retried, if yes, retry it. Otherwise, // throw the exception directly. }
// Clean-up & delay for a while before retrying. cleanupBeforeRetrying(); delay(); } } |
- call A.dosomething() to execute some logical.
- If A.dosomething() raise exception C, that means some special case happen, B should process dedicated use case.
- Class B invoke Class A to do something.
- Intercaptor will catch the exception C raised by A and mark Transaction "rollback only" once reach max retry number.
- Intercaptor delegate exception C to class B,
- Class B executed completely and try to submit the Transaction.
- Transaction rollback as it is marked "Rollback Only".
- Do not set point-cut on class A.
- Or do not use exception as business logical condition.
- Or use some other adapter who provide same behavior but has no that transaction interceptor. It is like first workaround.
- There are some Interceptors/Advisors which are not defined by myself.
发表评论
-
javax.naming.CommunicationException: remote side declared peer gone on this JVM.
2012-07-11 09:44 2379javax.naming.ServiceUnavailable ... -
Generate special format numbers
2012-04-27 00:06 940DecimalFormat df = new DecimalF ... -
Singleton Service in Weblogic Cluster
2012-03-21 00:12 712http://blog.csdn.net/mobicents/ ... -
Scheduled ThreadPool Executor suppressed or stopped after error happen
2012-03-20 16:54 1044ScheduledThreadPoolExecutor ... -
Bad version number in .class file
2012-01-27 00:35 896Bad version number in .class fi ... -
User Data Header in SMPP SUBMIT_SM
2012-01-25 22:30 2333SMPP optional Parameters for ... -
jQuery study
2011-12-28 00:44 0to be study -
Java is Pass-by-Value or Pass-by-Reference?
2011-12-19 19:18 688What's saved in Object Referenc ... -
java.util.Properties: a subclass of java.util.Hashtable
2011-12-13 06:57 777I met a problem this afternoon ... -
Jmock usage
2011-12-02 05:37 0Discuss how Jmock working. -
Oracle Index Usage
2011-12-15 05:26 628Like a hash mapping for record' ... -
AOP(2):AOP与动态代理JDK Proxy and Cglib Proxy
2011-05-12 16:20 1031使用动态代理(JDK Proxy 或者Cglib Proxy) ... -
异步系统设计:push vs pull
2011-05-02 23:59 1139今天讨论问题时,有个同事说系统A是主动去系统B里“拿”消息,我 ... -
Velocity Usage
2011-04-28 22:52 1006You can find velocity mannua ... -
Java Regular Expression (Java正则表达式)
2011-04-23 06:58 933In current Project, we need to ... -
XML Parser:DOM + XPath
2011-04-23 06:30 1203There are many kinds of XML Par ... -
File upload and download in Java Web Application.
2011-04-21 21:08 1715最近在项目中遇到一个下载文件的老问题。之所以说是老问题,因为在 ... -
Manage zip content using Java APIs
2011-04-21 18:14 1042JDK provide a set of utils to c ... -
Beanshell: how and where to use beanshell
2011-04-21 00:33 2096How to use beanshell beansh ... -
OXM: JAXB2.0 in JDK1.6
2011-04-20 22:53 12411.1.1 JAXB 2.0: ObjectàXML ...
相关推荐
AOP联盟:aopalliance.jar API包a set of AOP Java interface .
标题 "aop:aspect" 指涉的是Spring框架中的面向切面编程(Aspect-Oriented Programming, AOP)的一个核心概念。在Spring AOP中,`aop:aspect`是XML配置中定义一个切面的元素,它允许我们将关注点(如日志、事务管理...
AOP Alliance是一个在Java生态中广泛使用的开源项目,其1.0版本的发布对于理解和实践面向切面编程(Aspect-Oriented Programming,AOP)具有重要意义。本资源"aopalliance-1.0.rar"包含了这个关键版本的所有内容,是...
开发工具 aopalliance-1.0开发工具 aopalliance-1.0开发工具 aopalliance-1.0开发工具 aopalliance-1.0开发工具 aopalliance-1.0开发工具 aopalliance-1.0开发工具 aopalliance-1.0开发工具 aopalliance-1.0开发工具...
在Spring AOP中,主要有以下几个关键概念: 1. **切面(Aspect)**:定义了一个关注点的所有组件,包括通知(Advice)、切入点(Pointcut)和织入(Weaving)。 2. **通知(Advice)**:在特定连接点(Join Point...
AOP提供了一种强大的机制,允许开发者将横切...通过Spring AOP或AspectJ,我们可以轻松地在Java应用程序中实现AOP。理解AOP的工作原理和核心概念,可以帮助我们更好地利用这一强大的工具,编写出更加清晰、高效的代码。
在实际应用中,`MethodInterceptor`通常与`org.springframework.aop.framework.ProxyFactoryBean`或`org.aspectj.lang.ProceedingJoinPoint`等具体实现结合使用。`ProxyFactoryBean`是Spring AOP中的一个关键组件,...
在Spring框架中,AOP(面向切面编程)是一种强大的工具,它允许程序员将关注点分离,例如日志记录、事务管理、权限检查等,从核心业务逻辑中解耦出来。本篇主要探讨的是如何利用Spring AOP的注解来实现这些功能,...
在源码解析中,我们通常会关注以下几个关键点: 1. 切面类的解析:如何识别和处理切面类,提取切点和通知信息。 2. 创建代理:根据目标对象的类型选择JDK动态代理或CGLIB代理,并生成相应的代理类。 3. 代理类的调用...
在实际应用中,Spring AOP还支持多种类型的通知,如前置通知(Before)、后置通知(After)、返回通知(After Returning)、异常通知(After Throwing)和环绕通知(Around)。环绕通知可以通过实现`org.aopalliance...
1. **配置AOP支持**:在Spring的配置文件(如`applicationContext.xml`)中,开启AOP代理。可以使用`<aop:aspectj-autoproxy/>`标签来启用基于注解的AOP支持。 2. **定义切面**:创建一个Java类,该类代表切面,...
在Spring AOP中,主要有以下几个核心概念: 1. **切面(Aspect)**:切面是关注点的模块化,包含pointcut(切点)和advice(通知)两部分。例如,在上述代码中的`PersonProxy`类就是一个切面,它定义了`before()`和...
本示例将深入探讨Spring AOP的基础知识,以及如何在实际应用中使用它。 首先,我们来看"LogProfilter.java",这很可能是实现一个日志拦截器的类。在Spring AOP中,这样的类通常被称为切面(Aspect)。切面是封装了...
1. **启用 AspectJ 注解支持**:为了在 Spring 应用中使用 AspectJ 注解,需要确保项目 classpath 下包含了必要的 AspectJ 类库,包括 `aopalliance.jar`、`aspectjweaver.jar` 等。 2. **配置 AspectJ 切面**:...
### AOP技术在J2EE系统构建中的应用 #### 一、引言 在软件开发过程中,特别是构建大型的企业级应用时,系统中往往会存在一些跨多个模块的功能需求,例如事务管理、日志记录、安全控制等。这些功能通常被称为**横切...
在IT行业中,Spring框架是Java开发中的一个核心组件,尤其在企业级应用中广泛应用。Spring 1.x版本虽然已经较为古老,但理解其AOP(面向切面编程)的使用对于学习Spring框架的整体架构和设计理念至关重要。AOP是...
/beans>四、基于 XML 配置进行 AOP 开发:在 XML 文件中配置切面、通知、切入点等信息,例如:<aop:config><aop:aspect id="myInterceptor" ref="myInterceptorBean"><aop:before method="doAccessCheck" pointcut=...