spring-AOP

/*

 * AOP面向切面编程   

 * 切面    

切点  泛指所有的点

连接点    一个具体的点

通知

 * 前置通知-->save*()-->后置通知

 * 1.首先根据切点进行对应方法的监控

 * 2.然后当监控的方法真正执行的时候再来找到我们对应的通知,执行通知对应的方法

 * 3.顺序为前置通知-->执行的方法-->后置通知

 */


	<aop:config>
		<aop:aspect ref="firstAop">
			<!-- <aop:before method="befores" pointcut-ref="fristPoint"/>
			<aop:after method="after" pointcut-ref="fristPoint"/>
			<aop:after-returning method="returning" returning="result" pointcut-ref="fristPoint"/>
			<aop:after-throwing method="throwing" throwing="ex" pointcut-ref="fristPoint"/> --> 
			<aop:around method="around"  pointcut-ref="fristPoint"/>
			<!-- 根据表达式来确定我们的方法的监控名单 -->
			<aop:pointcut expression="execution(* com.lanou.service.impl.UserServiceImpl.*(..))" id="fristPoint"/>		
		</aop:aspect>
	</aop:config>

	public void around(ProceedingJoinPoint joinPoint) {
		try {
			System.out.println("前置通知");
			Object result = joinPoint.proceed();
			System.out.println("result:"+result);
			System.out.println("后置返回通知");
		} catch (Throwable e) {
			// TODO Auto-generated catch block
			System.out.println("后置异常通知");
			e.printStackTrace();
		}finally {
			System.out.println("后置通知");
		}
	}

事务管理:

	<!-- 事务管理 -->
	<!--		1.创建事务对象,将sessionfactory交给他管理 	
	 -->
	<bean id="tx" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
		<property name="sessionFactory" ref="sessionFactory"></property>
	</bean>
	<tx:advice id="advice" transaction-manager="tx">
		<tx:attributes>
			<!-- 设置为只读,将不再为其开启事务 -->
			<tx:method name="select*" read-only="true"/>
			<tx:method name="*" propagation="REQUIRED"/>
		</tx:attributes>
	</tx:advice>
	<aop:config>
		<aop:pointcut expression="execution(* com.lanou.dao.*.*(..))" id="txCut"/>
		<aop:advisor advice-ref="advice" pointcut-ref="txCut"/>
	</aop:config>


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值