aop-xml-环绕增强
生活随笔
收集整理的這篇文章主要介紹了
aop-xml-环绕增强
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
xml代碼
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans"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:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop.xsd"><bean id="mtm" class="cn.zj.spring.util.MyTransactionManager"></bean><bean id="service" class="cn.ljs.spring.service.impl.UserServiceImpl"></bean><aop:config><aop:pointcut expression="execution(* cn.zj.spring..*.*(..))" id="exp"/><aop:aspect ref="mtm"><aop:around method="allMethod" pointcut-ref="exp"/></aop:aspect></aop:config></beans>工具類代碼
package cn.ljs.spring.util;import org.aspectj.lang.JoinPoint; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Pointcut;public class MyTransactionManager {public void allMethod(ProceedingJoinPoint jp) {try {System.out.println("開始事務(wù)");jp.proceed();System.out.println("提交事務(wù)");} catch (Throwable e) {// TODO Auto-generated catch blockSystem.out.println("回滾事務(wù)");e.printStackTrace();} finally {System.out.println("關(guān)閉session");}}}
轉(zhuǎn)載于:https://www.cnblogs.com/heviny/p/10999820.html
總結(jié)
以上是生活随笔為你收集整理的aop-xml-环绕增强的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 一个页面是否应该全部组件化
- 下一篇: BackgroundWorker