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.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://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);
} }

spring 使用XML配置开发Spring AOP的更多相关文章

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

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

  2. Spring 基于xml配置方式的AOP(8)

    1.ArithmeticCalculator.java 1 package com.proc; 2 3 public interface ArithmeticCalculator { 4 int ad ...

  3. Spring Aop(七)——基于XML配置的Spring Aop

    转发:https://www.iteye.com/blog/elim-2396043 7 基于XML配置的Spring AOP 基于XML配置的Spring AOP需要引入AOP配置的Schema,然 ...

  4. SpringBoot零XML配置的Spring Boot Application

    Spring Boot 提供了一种统一的方式来管理应用的配置,允许开发人员使用属性properties文件.YAML 文件.环境变量和命令行参数来定义优先级不同的配置值.零XML配置的Spring B ...

  5. spring+mybaits xml配置解析----转

    一.项目中spring+mybaits xml配置解析 一般我们会在datasource.xml中进行如下配置,但是其中每个配置项原理和用途是什么,并不是那么清楚,如果不清楚的话,在使用时候就很有可能 ...

  6. spring的xml配置声明以及相应的问题处理

    spring的xml配置声明:  xml配置声明 Code 问题处理 问题1 xml报错: cvc-elt.1: Cannot find the declaration of element 'bea ...

  7. spring中用xml配置构造注入的心得

    spring中用xml配置构造注入时,如果 <constructor-arg> 属性都是 ref ,则不用理会参数顺序 <constructor-arg ref="kill ...

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

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

  9. Spring 使用xml配置aop

    1.xml文件需要引入aop命名空间 2.xml内容: <?xml version="1.0" encoding="UTF-8"?> <bea ...

随机推荐

  1. vue自定义元素拖动

    岗位序列拖动交换岗位 <span draggable="true" @dragstart="onDragstart($event,index,index2)&quo ...

  2. jquery操作按钮修改对应input属性

    点击右侧的修改按钮,对应的input中的disabled和readonly得属性修改 $(".buttonxg button").click(function(){ $(this) ...

  3. 【CSP-S 2019】【洛谷P5665】划分【单调队列dp】

    前言 \(csp\)时发现自己做过类似这道题的题目 : P4954 [USACO09Open] Tower of Hay 干草塔 然后回忆了差不多\(15min\)才想出来... 然后就敲了\(88p ...

  4. PostgreSQL的 pg_hba.conf 配置参数详解

    pg_hba.conf 配置详解 该文件位于初始化安装的数据库目录下 编辑 pg_hba.conf 配置文件   postgres@clw-db1:/pgdata/9.6/poc/data> v ...

  5. mysql sum的多条件求和

    1.无条件求和 sum(字段名): 2.多条件求和 sum(IF(c1>0, c1, 0)); (IF(o.is_cod=0,o.order_amount-IF(b.back_status> ...

  6. 飞扬的小鸟 DP

    飞扬的小鸟 DP 细节有点恶心的DP,设\(f[i][j]\)表示横坐标为\(i\)(从\(0\)开始)高度为\(j\)时,屏幕点击的最小次数为\(f[i][j]\),转移便很好写了,这里要注意枚举当 ...

  7. ArcGIS分支版本化( Branch Versioning )技术介绍

    概述 分支版本化技术是有别于传统的SDE版本化技术,它用于支持WebGIS模式下的多用户长事务编辑. 优势功能 使用分支版本化技术将获得以下功能 1. 支持长事务的编辑. 2. 支持Undo和Redo ...

  8. (16)打鸡儿教你Vue.js

    博客: Hexo搭建个性博客 https://hexo.io/zh-cn/ 快速.简洁且高效的博客框架 超快速度 Node.js 所带来的超快生成速度,让上百个页面在几秒内瞬间完成渲染. 支持 Mar ...

  9. Three.js中的group,obj,模型中layers层级与相机

    目录 Three.js中的group,obj,模型中layers层级与相机 layers group中的.layers.mask设置 一些设想 Three.js中的group,obj,模型中layer ...

  10. Sublime Text 3 import Anaconda 无法正常补全模块名解决办法

    Sublime Text 3 Anaconda配置 在安装Sublime Text3之后我们总会安装一些插件,比如Python的Anaconda自动补全插件.但是,装好之后发现import 时无法像别 ...