spring aop 第二种方式--xml配置

  1. <?xml version="1.0" encoding="UTF-8"?>  
  2.   
  3. <beans xmlns="http://www.springframework.org/schema/beans"  
  4.          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  5.          xmlns:aop="http://www.springframework.org/schema/aop"  
  6.          xmlns:tx="http://www.springframework.org/schema/tx"  
  7.          xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd  
  8.            http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd  
  9.            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">  
  10.                
  11.       
  12.     <bean id="userManager" class="com.tgb.aop.UserManagerImpl"/>  
  13.       
  14.     <!--<bean id="aspcejHandler" class="com.tgb.aop.AspceJAdvice"/>-->  
  15.     <bean id="xmlHandler" class="com.tgb.aop.XMLAdvice" />  
  16.     <aop:config>  
  17.         <aop:aspect id="aspect" ref="xmlHandler">  
  18.             <aop:pointcut id="pointUserMgr" expression="execution(* com.tgb.aop.*.find*(..))"/>  
  19.               
  20.             <aop:before method="doBefore"  pointcut-ref="pointUserMgr"/>  
  21.             <aop:after method="doAfter"  pointcut-ref="pointUserMgr"/>  
  22.             <aop:around method="doAround"  pointcut-ref="pointUserMgr"/>  
  23.             <aop:after-returning method="doReturn"  pointcut-ref="pointUserMgr"/>  
  24.             <aop:after-throwing method="doThrowing" throwing="ex" pointcut-ref="pointUserMgr"/>  
  25.               
  26.         </aop:aspect>  
  27.     </aop:config>  
  28. </beans> 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
代码报错<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:comtext="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd"> <!-- 1 准备目标类 --> <bean id="personDao" class="com.sc.spring.dao.impl.PersonDaoImpl"></bean> <!-- 2 准备增强类 --> <bean id="myAdvice" class="com.sc.spring.utils.MyAdvice"></bean> <!-- 3 织入 将增强类的增强方法应用到目标类的目标方法前后 --> <aop:config> <!-- pointcut标签声明切入点表达式 切入点表达式就是一种规则 spring aop根据规则找到满足规则的目标方法 然后对目标方法前后进行指定增强 --> <aop:pointcut id="pc" expression="execution(public boolean com.sc.spring.dao.impl.PersonDaoImpl.getPersonByUsernameAndPwd(java.lang.String,java.lang.String))"></aop:pointcut> <aop:aspect ref="myAdvice"> <!-- aop:before标签代表配置前置通知 method属性是配置增强类中哪个方法作为前置通知执行 --> <aop:before method="before" pointcut-ref="pc"></aop:before> </aop:aspect> </aop:config> </beans>报错问题是org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 22 in XML document from class path resource [aop.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 22; columnNumber: 17; cvc-complex-type.2.4.c: 通配符的匹配很全面, 但无法找到元素 'aop:config' 的声明。
06-06

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值