和Spring1.X相比,Spring2.X使用AspectJ的语法来声明AOP,这使得它更“标准”,更灵活了。
AspectJ的配置方法有二种:
一种是在applicationContext.xml中配置
java 代码
- "1.0" encoding="UTF-8"?> 在使用Spring的AOP编程时,会用到这几个lib:
asm-2.2.2.jar
asm-commons-2.2.2.jar
asm-util-2.2.2.jar
Hibernate使用如果lib:
asm.jar
asm-attrs.jar
其中asm-2.2.2.jar与asm.jar存在类上的冲突!!!
使用其中之一或两者都使用,可能会出现如下错误:
java.lang.NoClassDefFoundError: org/objectweb/asm/CodeVisitor
java.lang.NoClassDefFoundError: org/objectweb/asm/commons/EmptyVisitor
java.lang.NoSuchMethodError: org.objectweb.asm.ClassVisitor.visit。。。。。。
解决办法是:
1.去掉类路径上的关于Hibernate的3个lib
asm.jar
asm-attrs.jar
cglib-2.1.3.jar
2.加入Spring中的以下4个lib
asm-2.2.2.jar
asm-commons-2.2.2.jar
asm-util-2.2.2.jar
cglib-nodep-2.1_3.jar- "http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:aop="http://www.springframework.org/schema/aop"
- xmlns:tx="http://www.springframework.org/schema/tx"
- xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
- http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
- http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd"
- default-autowire="byName" default-lazy-init="true">
- "propertyConfigurer"
- class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
- "locations">
- <list></list>
- <value></value>classpath*:config/jdbc.properties
- <value></value>classpath*:config/hibernate.properties
- <value></value>classpath*:config/mail.properties
- <aop:advisor span=""> </aop:advisor>
- pointcut="execution(* org.springside.core.dao.*Dao.*(..))"
- advice-ref="txAdvice" />
- <tx:attributes> </tx:attributes>
- <aop:config> </aop:config>
- ref="workflowHistoryImpl">
- expression="execution(* cn.grgbanking.view..*Impl.saveData(..)) and args(request)" />
- method="saveHistory" />
- "workflowHistoryImpl"
- class="cn.grgbanking.wfms.impl.WorkflowHistoryImpl">