想在dao中的某个方法之前和之后做一些处理,
发现不起作用。

解决方案 »

  1.   

    <?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:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    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-3.0.xsd
           http://www.springframework.org/schema/context 
           http://www.springframework.org/schema/context/spring-context-3.0.xsd
           http://www.springframework.org/schema/tx 
           http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
           http://www.springframework.org/schema/aop
           http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
    <!--    <aop:aspectj-autoproxy proxy-target-class="true"/>-->    <context:component-scan base-package="com.eta.dao"/>
        <context:component-scan base-package="com.eta.service"/>
           
        <!-- 打开aop 注解 -->
        <aop:aspectj-autoproxy />
    没有别的配置
      

  2.   

        <aop:config >  
            <aop:aspect id="myListener" ref="TestAspect">  
               <aop:pointcut expression="execution(* com.dao.*.*(..))" id="listenerCut"/>               
               <aop:around method="joinPointAccess" pointcut-ref="listenerCut"/>
            </aop:aspect>   
        </aop:config>
    好奇怪  com.dao.*.*(..)  就可以出发切面方法,把dao改成别的目录就不触发了
      

  3.   

    你这样配置只是拦截com.dao.*下的类,而不会拦截它的子包下的类,如com.dao.impl.*
    如果想扫描com.dao下的所有包,应该这样表达式应该是execution(* com.dao..*.*(..))