Spring学习心得(五)

 

Spring学习心得(五)

1.       advice细粒度的控制,可以通过pointcut类来控制。

2.       advisoradvicepointcut的集合体。

3.       控制方法如下:

a)       定义Pointcut中的ClassFilter实现类和MethodMatcher实现类,完成对classmethod方法的advice的控制,其中MethodMatcher中的matches(Method method, Class targetClass)方法是对classmethod的双重并集控制

b)      定义新的Pointcut实现类,并将ClassFilter实现类和MethodMatcher实现类赋值

c)       定义新的advisor并且实现PointcutAdvisor接口

d)      在定义的advisor中使用PointcutAdvisor接口中的getPointcut()getAdvice()Pointcut的实现类和需要的advice进行传递

e)       最后在application-context.xml中将

<bean id="XXXX"

class="org.springframework.aop.framework.ProxyFactoryBean">

      <property name="InterceptorNames">

           <list>

                 <idref local="定义新的advisorid">

           </list>

      <property>

</bean>

<bean id="定义新的advisorid" class="定义新的advisor的类     " >

</bean>

4.       为了使用静态的Pointcut,可以使用StaticMethodMatcherPointcut,这时候

public final boolean isRuntime()

    {

        return false;

}

便不能修改了。也就是静态的Pointcut

5.       更简单的是使用NameMatchMethodPointcutAdvisor,这里一个advisor只有一个advice

 

v

posted on 2007-09-05 16:50 刘铮 阅读(203) 评论(0)  编辑  收藏 所属分类: Spring


只有注册用户登录后才能发表评论。


网站导航:
 
<2024年5月>
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

导航

统计

留言簿(1)

文章分类(141)

文章档案(147)

搜索

最新评论