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. 项目后端 - 虚拟环境搭建 | pycharm使用虚拟环境

    虚拟环境的搭建 优点 1.使不同应用开发环境相互独立 2.环境升级不影响其他应用,也不会影响全局的python环境 3.防止出现包管理混乱及包版本冲突 windows 安装 # 建议使用pip3安装到 ...

  2. restful接口规范 | 基于restful的原生django接口

    restful接口规范 接口 接口:联系两个物质的媒介,完成信息交互 web程序中:联系前台页面与后台数据库的媒介 web接口组成: - url:长得像返回数据的url链接 - 请求参数:前台按照指定 ...

  3. Set的常用实现类HashSet和TreeSet

    Set HashSet public static void main(String[] args) { //不可以重复  并且是无序的  //自然排序  从A-Z  //eqauls从Object继 ...

  4. boost.tribool

    tribool boost.tribool类似c++内建的bool类,但基于三态的布尔逻辑,在true和false之外还有一个indeterminate状态.一个例子场景是执行某项任务,在执行之前状态 ...

  5. Excel、CSV文件处理

    1.Excel中以\t做为列分隔符,换行符作为行分隔符 使用c#导出excel的时候,当数字太长时,如身份证号,导出后的excel就会显示为科学计数法.如“511122154712121000”会显示 ...

  6. nginx和php整合安装过程记录

    1.nginx的配置:必须是指定 www用户 和www用户组访问 groupadd www useradd -g www www daokr@DK:~$ cat /etc/nginx/nginx.co ...

  7. 洛谷P5017摆渡车

    题目 一道做法多种多样的题,DP做法的状态也很多. 我用\(dp[i]\)表示在第i秒发车的时间和,然后dp方程就很好写了 \(dp[i] = dp[j] + i车的等待时间\)j属于i-2m ~ i ...

  8. 微信小程序微信登录

    开发接口 登录 wx.login wx.checkSession 签名加密 小程序登录 小程序可以通过微信官方提供的登录能力方便地获取微信提供的用户身份标识,快速建立小程序内的用户体系. 登录流程时序 ...

  9. shell编程练习题

    求2个数之和 计算1-100的和 将一目录下所有的文件的扩展名改为bak 编译当前目录下的所有.c文件: 打印root可以使用可执行文件数,处理结果: root's bins: 2306 打印当前ss ...

  10. word 新建一行文字不能左对齐