Spring AOP给系统做日志
环境:Spring1.2.6 JDK1.4
applicationContext.xml文件配置参照如下
<beans>
  <bean id="theBeforeAdvice" class="com.company.springaop.test.TestBeforeAdvice"/>
  <bean id="beanTarget" class="com.company.springaop.test.BeanImpl"/>
  <bean id="bean" class="org.springframework.aop.framework.ProxyFactoryBean">
    <property name="proxyInterfaces">
      <value>com.company.springaop.test.Bean</value>
    </property>
    <property name="target">
      <ref local="beanTarget"/>
    </property>
    <property name="interceptorNames">
      <list>
        <value>theAdvisor</value>
      </list>
    </property>
  </bean>
  <bean id="theAdvisor" class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">
    <property name="advice">
      <ref local="theBeforeAdvice"/>
    </property>
    <property name="patterns">
      <list>
        <value>com.company.springaop.test.Bean.theMethod</value>
      </list>
    </property>
  </bean>
</beans>
但是如果我不用'theAdvisor'直接用 'theBeforeAdvice'每个方法都拦截能行,
但是添加了正则表达式方法拦截却不起作用,是怎么回事啊
我现在就是想要拦截指定的类指定的方法....

解决方案 »

  1.   


    <bean id="aophello" class="com.njtysoft.spring1x.proxy.BeforeAfterHello"></bean>
    <aop:config>
    <aop:aspect id="aop" ref="aophello">
    <aop:pointcut id="xhj" expression="execution(void com.njtysoft.spring1x.proxy.Hello.display())"/>

    <aop:before method="before" pointcut-ref="xhj"/>
    <aop:after method="after" pointcut-ref="xhj"/>
    </aop:aspect>
    </aop:config> 
      

  2.   

    <aop:config>
       <aop:advisor pointcut="execution(* com.test.TestService.*(..))" advice-ref="txAdvice" /> 
    </aop:config> <!--  事务拦截 -->
    <tx:advice id="txAdvice">
    <tx:attributes>
    <tx:method name="insert*" propagation="REQUIRED" /> //所有以insert为前缀的方法
    </tx:attributes>
    </tx:advice>