- Java code
<?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:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd"> <bean id="sr" class="com.springmodel.Shiren" /> <bean id="qs" class="com.springmodel.Qishi"> </bean> <aop:config> <aop:aspect ref="sr" > <aop:pointcut id="qeMethod" expression="execution(* com.springmodel.Qishi.tanXian(*))" /> <aop:before method="singBefore" pointcut-ref="qeMethod"/> <aop:after method="singAlter" pointcut-ref="qeMethod"/> </aop:aspect> </aop:config></beans>
- Java code
package com.springmodel;public class Shiren { public void singBefore(){ System.out.println("探险之前sing"); } public void singAlter(){ System.out.println("探险之后sing"); }}
程序能够运行成功过,但是这2条语句
- Java code
<aop:before method="singBefore" pointcut-ref="qeMethod"/> <aop:after method="singAlter" pointcut-ref="qeMethod"/>
运行没有效果
------解决方案--------------------
晕,怎么看不见哦。
<aop:pointcut id="qeMethod" expression="execution(* com.springmodel.Qishi.tanXian(*))" />
这个导致的,改成
<aop:pointcut id="qeMethod" expression="execution(* com.springmodel.Qishi.tanXian(..))" />或者
<aop:pointcut id="qeMethod" expression="execution(* com.springmodel.Qishi.tanXian())" />
试试吧