`

第十章 Spring AOP之通知

阅读更多

AOP之通知:

通过配置spring,将通知切入在方法执行前或后,添加打印日志信息,异常信息,获取类名,方法名,参数等

1,前置通知;
2,后置通知;
3,环绕通知;
4,返回通知;
5,异常通知;



<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/aop
        http://www.springframework.org/schema/aop/spring-aop.xsd">
	
	<!-- 定义通知 -->
	<bean id="studentServiceAspect" class="com.fx.advice.StudentServiceAspect"></bean>
	
	<!-- 定义业务类 -->
	<bean id="studentService" class="com.fx.service.impl.StudentServiceImpl"></bean>
	
	<!-- 业务类配置通知 -->
	<aop:config>
		<aop:aspect id="studentServiceAspect" ref="studentServiceAspect">
			<!-- 切点表达式,匹配包路径下的java -->
			<aop:pointcut expression="execution(* com.fx.service.*.*(..))" id="businessService"/>
			<!-- 前置通知 -->
			<aop:before method="doBefore" pointcut-ref="businessService"/>
			<!-- 后置通知 -->
			<aop:after method="doAfter" pointcut-ref="businessService"/>
			<!-- 环绕通知 -->
			<aop:around method="doAround" pointcut-ref="businessService"/>
			<!-- 返回通知 -->
			<aop:after-returning method="doAfterReturning" pointcut-ref="businessService"/>
			<!-- 异常通知 -->
			<aop:after-throwing method="doAfterThrowing" pointcut-ref="businessService" throwing="ex"/>
		</aop:aspect> 
	</aop:config>
</beans>

分享到:
评论

相关推荐

    MyEclipse 6 Java 开发中文教程第十章

    ### MyEclipse 6 Java 开发中文教程第十章:开发Spring应用 #### 10.1 简介 在本章中,我们将探讨如何使用MyEclipse 6开发Spring框架的应用程序。Spring是一个轻量级的开源框架,用于简化企业级Java应用程序的开发...

    springlive(共11章)

    10. **第十章:Spring Security** - 认证与授权:理解身份验证和授权的基本概念,以及Spring Security提供的安全机制。 - 自定义安全配置:学习如何根据需求定制Spring Security的配置,保护应用程序的安全。 11....

    Spring框架高级编程源代码

    1. **AOP(面向切面编程)**:Spring的重要特性之一是其强大的AOP支持,它允许开发者在不修改原有代码的情况下,对程序进行横切关注点的管理,如日志、事务管理等。在第十章中,你将学习如何定义和配置切面,以及...

    跟我学spring

    【第十章】集成其它Web框架。Spring的灵活性允许它与其他流行的Web框架集成。10.1节概述集成其他Web框架,10.2节介绍如何集成Struts1.x,10.3节介绍如何集成Struts2.x,10.4节介绍如何集成JSF(JavaServer Faces)。...

    spring2.0核心技术最佳实践源代码

    通过阅读和分析《Spring 2.0核心技术最佳实践源代码》第十章的源代码,开发者不仅能学习到Spring的核心概念,还能掌握如何在实际项目中运用这些技术,提升开发效率和代码质量。同时,这也有助于开发者对Spring框架有...

    spring.net中文手册在线版

    第十章. 表达式求值 10.1.简介 10.2.表达式求值 10.3.语言参考 10.3.1.文字表达式 10.3.2.属性,数组,列表,字典,索引器 10.3.2.1.定义内联的数组、列表和词典 10.3.3.方法 10.3.4.操作符 10.3.4.1.关系操作符 ...

    MyEclipse 6 Java开发教程10-12

    第十章“开发Spring应用”主要介绍Spring框架的基础知识。Spring是一个轻量级的开源框架,它的核心特性是依赖注入(Dependency Injection,DI)和面向切面编程(Aspect-Oriented Programming,AOP)。这一章可能涵盖...

    《MyEclipse 6 Java 开发中文教程》前10章

    第十章 开发Spring应用 198 10.1 简介 198 10.1.1 Spring简介 198 10.1.2 MyEclipse的Spring开发功能简介 200 10.2 开发简单的Spring应用 200 10.2.1 给项目加入Spring功能 200 10.2.2 创建Bean类和配置信息 202 ...

Global site tag (gtag.js) - Google Analytics