spring拦截器学习小结

为了实现网站的日志管理,研究了几天的spring事务管理终于OK了!两种方法

方法一:实现对目标类进行拦截(对于有 的类,使用的是Java内部类提供的Proxy;而对于那些不实现接口 的类,使用的是cglib库)

xml 代码
  1. <!-- Bean configuration -->   
  2.    < bean   id = "businesslogicbean"   
  3.     class = "org.springframework.aop.framework.ProxyFactoryBean" >   
  4.       < property   name = "proxyInterfaces" >   
  5.          < value > IBusinessLogic </ value >   
  6.       </ property >   
  7.       < property   name = "target" >   
  8.          < ref   local = "beanTarget" />   
  9.       </ property >   
  10.       < property   name = "interceptorNames" >   
  11.          < list >   
  12.             < value > theAroundAdvisor </ value >   
  13.          </ list >   
  14.          </ property >   
  15.    </ bean >   
  16.    <!-- Bean Classes -->   
  17.    < bean   id = "beanTarget"   
  18.     class = "com.safetys.service.UserService" />   
  19.   
  20.    <!-- Advisor pointcut definition for around advice -->   
  21.    < bean   id = "theAroundAdvisor"   
  22.        class = "org.springframework.aop.support.RegexpMethodPointcutAdvisor" >   
  23.       < property   name = "advice" >   
  24.          < ref   local = "theAroundAdvice" />   
  25.       </ property >   
  26.       < property   name = "pattern" >   
  27.          < value > .* </ value >   
  28.       </ property >   
  29.    </ bean >   
  30.     
  31.    <!-- Advice classes -->   
  32.    < bean   id = "theAroundAdvice"   
  33.        class = "com.safetys.iface.TestBeforeAdvice" />   

 

方法二:拦截ACTION(我现在用的就是这方法)

xml 代码
  1. < bean   id = "actionBeanNameProxyCreator"      
  2. class = "org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator" >      
  3. < property   name = "beanNames" > < value > *Action </ value > </ property >      
  4. < property   name = "interceptorNames" >      
  5. < list >      
  6. < value > theBeforeAdvice </ value >      
  7. </ li  st >      
  8. </ property >      
  9. </ bean >     
  10. < bean   id = "theBeforeAdvice"   class = "com.safetys.iface.TestBeforeAdvice" />  

你可能感兴趣的:(spring,AOP,bean,xml)