XML方式开发AOP与注解开发原理是相同的,所以这里主要介绍一些用法即可。这里需要在XML中引入AOP的命名空间,所以先来了解一下AOP可配置的元素

  代码清单:切面类

package com.ssm.chapter11.xml.aspect;public class XmlAspect {public void before() {System.out.println("before ......");}public void after() {System.out.println("after ......");}public void afterThrowing() {System.out.println("after-throwing ......");}public void afterReturning() {System.out.println("after-returning ......");}}

  没有任何的注解,这就意味着需要我们使用XML去向Spring IoC容器描述它们。

  代码清单:spring-cfg4.xml

<?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:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd"><bean id="xmlAspect" class="com.ssm.chapter11.xml.aspect.XmlAspect"/><bean id="roleService" class="com.ssm.chapter11.xml.service.impl.RoleServiceImpl"/><aop:config><!-- 引用xmlAspect作为切面 --><aop:aspect ref="xmlAspect"><!-- 定义切点 --><aop:pointcut id="printRole" expression="execution(* com.ssm.chapter11.xml.service.impl.RoleServiceImpl.printRole(..))"/><!-- 定义通知,引入切点 --><aop:before method="before" pointcut-ref="printRole"/><aop:after method="after" pointcut-ref="printRole"/><aop:after-throwing method="afterThrowing" pointcut-ref="printRole"/><aop:after-returning method="afterReturning" pointcut-ref="printRole"/><aop:around method="around" pointcut-ref="printRole"/></aop:aspect></aop:config></beans>

  代码清单:测试类

public class Main {public static void main(String[] args) {ApplicationContext ctx = new ClassPathXmlApplicationContext("ssm/chapter11/spring-cfg4.xml");RoleService roleService = ctx.getBean(RoleService.class);Role role = new Role();role.setId(1L);role.setRoleName("role_name_1");role.setNote("note_1");roleService.printRole(role);}}

转载于:https://www.cnblogs.com/ooo0/p/11018752.html

spring 使用XML配置开发Spring AOP相关推荐

  1. Spring 基于xml配置方式的AOP

    我们具体用代码来说明: 1.ArithmeticCalculator.java 1 package com.proc; 2 3 public interface ArithmeticCalculato ...

  2. SSM框架笔记06:初探Spring——采用XML配置方式

    初探Spring--采用XML配置方式   Spring框架是一个轻量级的企业级开发的一站式解决方案.所谓解决方案就是可以基于Spring解决Java EE开发的所有问题.Spring框架主要提供了I ...

  3. java application.xml_第4章 零XML配置的Spring Boot Application

    第4章 零XML配置的Spring Boot Application Spring Boot 提供了一种统一的方式来管理应用的配置,允许开发人员使用属性properties文件.YAML 文件.环境变 ...

  4. 一步一步深入spring(6)--使用基于XML配置的spring实现的AOP

    上节我们提到了使用基于注解实现的AOP,这节我们将用基于xml配置的方式来实现的AOP. 1.首先建立一个类,作为切面类,这个类主要用来实现注解中各种通知要实现的方法. 1 package com.y ...

  5. 基于注解的Spring MVC(所需jar包,web.xml配置,Spring文件配置,@Controller,@RequestMapping,@RequestParam,model填参,EL取值)

    1.添加jar 2.web.xml配置: <?xml version="1.0" encoding="UTF-8"?> <web-app ve ...

  6. 如何把Spring Boot 项目变成一个XML配置的Spring项目

    现在大家都追赶新的技术潮流,我来逆行一下. 其实Spring Boot 隐藏了大量的细节,有大量的默认配置,其实通过xml配置的方式也可以达到和Spring Boot一样的效果. Profile 在S ...

  7. Shiro Spring 集成xml配置

    JavaSE 应用: spring-shiro.xml 提供了普通 JavaSE 独立应用的 Spring 配置: <!-- 缓存管理器 使用Ehcache实现 --> <bean ...

  8. spring mvc xml配置

    首先来看web的xml配置 <!-- 改变接收编码,表单提交用post方法 -->   <filter>         <filter-name>encoding ...

  9. 基于XML配置的Spring MVC(所需jar包,web.xml配置,处理器配置,视图解析器配置)

    1.添加jar 2.web.xml配置 <?xml version="1.0" encoding="UTF-8"?> <web-app ver ...

最新文章

  1. elon函数_Neuroink Elon麝香制造中的灾难
  2. T-SQL编程基础之一:变量与基本语句
  3. html5中外描边怎么写,CSS3实现文字描边的2种方法(小结)
  4. Android 人脸识别进行实名验证demo
  5. sdio接口_单片机基础 —— 使用SDMMC接口读写SD卡数据
  6. Android APP功能测试(个人总结完整版)
  7. 广州的11个辖区_13张地形图,快速了解广东省广州市的11个市辖区
  8. ISO7637-2测试case汇总
  9. LINUX下打包jar
  10. 深挖Openstack Nova - evacuate疏散函数
  11. vue中引入高德地图并多点标注
  12. ubuntu 16.04 安装nvidia驱动 下载nvidia官方驱动
  13. 肿瘤精准细胞免疫治疗:梦想照进现实
  14. java微信昵称带表情的处理
  15. python的UnboundLocalError: local variable 'xxx' referenced b
  16. 笔记本电脑搜索不到wifi,只有飞行模式
  17. 74LS244 三态门 功能介绍
  18. 通用量子操作系统,收揽全球量子硬件20%市场份额
  19. matlab读取mp3文件并且播放
  20. CocoaPods——Cocoapods 入门

热门文章

  1. Linux 查看 占用内存最多 占用cpu最多 程序(类似top,监视)
  2. QT5_PYQT导入自己的图片
  3. 设计模式:装饰模式(C++)【小明习武闯天下】
  4. Windows server 2008 R2 服务器安装 MySql 5.6.36 64位绿色版 报系统错误1067
  5. 【搜索引擎】全文索引数据结构和算法
  6. redis配置文件参数详解
  7. 二、python基础
  8. 编程题练习 两个栈实现队列
  9. bzoj 1654: [Usaco2006 Jan]The Cow Prom 奶牛舞会 -- Tarjan
  10. PPT分享:用户画像场景与技术实现