为了实现网站的日志管理,研究了几天的spring事务管理终于OK了!两种方法
方法一:实现对目标类进行拦截(对于有接 口 的类,使用的是Java内部类提供的Proxy;而对于那些不实现接口 的类,使用的是cglib库)
xml 代码
-
- < bean id = "businesslogicbean"
- class = "org.springframework.aop.framework.ProxyFactoryBean" >
- < property name = "proxyInterfaces" >
- < value > IBusinessLogic </ value >
- </ property >
- < property name = "target" >
- < ref local = "beanTarget" />
- </ property >
- < property name = "interceptorNames" >
- < list >
- < value > theAroundAdvisor </ value >
- </ list >
- </ property >
- </ bean >
-
- < bean id = "beanTarget"
- class = "com.safetys.service.UserService" />
-
-
- < bean id = "theAroundAdvisor"
- class = "org.springframework.aop.support.RegexpMethodPointcutAdvisor" >
- < property name = "advice" >
- < ref local = "theAroundAdvice" />
- </ property >
- < property name = "pattern" >
- < value > .* </ value >
- </ property >
- </ bean >
-
-
- < bean id = "theAroundAdvice"
- class = "com.safetys.iface.TestBeforeAdvice" />
方法二:拦截ACTION(我现在用的就是这方法)
xml 代码
- < bean id = "actionBeanNameProxyCreator"
- class = "org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator" >
- < property name = "beanNames" > < value > *Action </ value > </ property >
- < property name = "interceptorNames" >
- < list >
- < value > theBeforeAdvice </ value >
- </ li st >
- </ property >
- </ bean >
- < bean id = "theBeforeAdvice" class = "com.safetys.iface.TestBeforeAdvice" />