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. Python文件的读写操作

    Python文件的使用 要点:Python能够以文本和二进制两种形式处理文件. 1.文件的打开模式,如表1:  注意:使用open()函数打开文件,文件使用结束后耀使用close()方法关闭,释放文件 ...

  2. 动态加载 ShellCode绕过杀软

    反病毒解决方案用于检测恶意文件,并且通常使用静态分析技术来区分二进制文件的好坏.如果是恶意文件本身包含恶意内容(ShellCode),那么依靠静态分析技术会非常有效,但如果攻击者使用轻量级的stage ...

  3. 洛谷 P2827 蚯蚓 题解

    每日一题 day32 打卡 Analysis 我们可以想一下,对于每一秒除了被切的哪一个所有的蚯蚓都增长Q米,我们来维护3个队列,队列1表示最开始的蚯蚓,队列2表示每一次被切的蚯蚓被分开的较长的那一部 ...

  4. Qt同步线程(QMutex QMutexLocker QReadWriteLock QSemaphore QWaitCondition )

    Qt同步线程 我们知道,多线程有的时候是很有用的,但是在访问一些公共的资源或者数据时,需要进行同步,否则会使数据遭到破坏或者获取的值不正确.Qt提供了一些类来实现线程的同步,如QMutex,QMute ...

  5. 51 Nod 1430 奇偶游戏(博弈)

    1430 奇偶游戏 题目来源: CodeForces 基准时间限制:1 秒 空间限制:131072 KB 分值: 160 难度:6级算法题 收藏 关注 有n个城市,第i个城市有ai个人.Daenery ...

  6. P3388 【模板】割点(割顶)&& 桥

    题目背景 割点 题目描述 给出一个n个点,m条边的无向图,求图的割点. 输入输出格式 输入格式: 第一行输入n,m 下面m行每行输入x,y表示x到y有一条边 输出格式: 第一行输出割点个数 第二行按照 ...

  7. Kindle Touch 修砖手札

    首先是网上的修砖教程: 最近有多人反映按照修砖程序走过后依然板砖,和碎平联系和WA沟通后对帖子作新的修改. 新教程直接使用5.1.2的镜像,特别说明. 特别感谢kn007的专业指导 小白帖子现为简化过 ...

  8. npm 更新包

    方法一手动跟新: 手动修改package.json中依赖包版本,执行npm install --force,强制从远程下载所有包更新本地包 方法二使用第三方插件: npm install -g npm ...

  9. VS2019输出信息到调试控制台

    System.Diagnostics.Debug.WriteLine(format, args);

  10. elasticsearch x-pack license过期

    1.注册一个新的license,每一项都要填写,每次可以使用一年,一年到期后再来注册一个新的 2.更新license (官方文档:https://www.elastic.co/guide/en/x-p ...