spring 使用XML配置开发Spring 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的更多相关文章
- Spring 基于xml配置方式的AOP
我们具体用代码来说明: 1.ArithmeticCalculator.java package com.proc; public interface ArithmeticCalculator { in ...
- Spring 基于xml配置方式的AOP(8)
1.ArithmeticCalculator.java 1 package com.proc; 2 3 public interface ArithmeticCalculator { 4 int ad ...
- Spring Aop(七)——基于XML配置的Spring Aop
转发:https://www.iteye.com/blog/elim-2396043 7 基于XML配置的Spring AOP 基于XML配置的Spring AOP需要引入AOP配置的Schema,然 ...
- SpringBoot零XML配置的Spring Boot Application
Spring Boot 提供了一种统一的方式来管理应用的配置,允许开发人员使用属性properties文件.YAML 文件.环境变量和命令行参数来定义优先级不同的配置值.零XML配置的Spring B ...
- spring+mybaits xml配置解析----转
一.项目中spring+mybaits xml配置解析 一般我们会在datasource.xml中进行如下配置,但是其中每个配置项原理和用途是什么,并不是那么清楚,如果不清楚的话,在使用时候就很有可能 ...
- spring的xml配置声明以及相应的问题处理
spring的xml配置声明: xml配置声明 Code 问题处理 问题1 xml报错: cvc-elt.1: Cannot find the declaration of element 'bea ...
- spring中用xml配置构造注入的心得
spring中用xml配置构造注入时,如果 <constructor-arg> 属性都是 ref ,则不用理会参数顺序 <constructor-arg ref="kill ...
- 一步一步深入spring(6)--使用基于XML配置的spring实现的AOP
上节我们提到了使用基于注解实现的AOP,这节我们将用基于xml配置的方式来实现的AOP. 1.首先建立一个类,作为切面类,这个类主要用来实现注解中各种通知要实现的方法. package com.yan ...
- Spring 使用xml配置aop
1.xml文件需要引入aop命名空间 2.xml内容: <?xml version="1.0" encoding="UTF-8"?> <bea ...
随机推荐
- python会缓存小的整数和短小的字符
经过测试,python会缓存的小整数的范围是 [-5, 256] # True a = 1 b = 1 print(a is b) # True a = "good" b = &q ...
- CSS hack整理
浏览器的兼容性一直是个头疼的问题,使用“欺骗”技术可使各个浏览器效果一致,花了些时间整理了各个浏览器的HACK,主要包括IE系列和最新版本的Chrome.Safari.Firefox. Opera,比 ...
- 求序列A中每个数的左边比它小的数的个数(树状数组)
给定一个有N个正整数的序列A(N<=10^5,A[i]<=10^5),对序列中的每一个数,求出序列中它左边比它小的数的个数. 思路:树状数组的经典应用(裸题) #include <i ...
- 指数基金介绍专栏(8):国企指数(H股指数)详细介绍,最新资料解析,看这一篇就够了
作者:牛大 | 公众号:定投五分钟 大家好,我是牛大.每天五分钟,投资你自己:坚持基金定投,终会财富自由! 昨天牛大给大家介绍了恒生指数,没看的朋友可以去公众号看一下. 指数基金介绍专栏(7):恒生指 ...
- 使用Optional优雅处理null
先假设一个场景.如下所示 public class Person { private String name; public Person() { } public Person(String nam ...
- luogu 3246 莫队+RMQ+单调栈
hnoi 2016 标签:题解 莫队 考虑左端点左移以及右端点右移产生的贡献 这样就可以由 \([l, r]\) 转移到另外的 \(4\) 个区间 \(f_{l, r}\) 表示右端点在 \(r\), ...
- 如何在Processing中用鼠标获取RGB颜色数值
要做一个抠图应用,所以随手做了个鼠标取色,代码如下: void mousePressed(){ int imgC = get(mouseX,mouseY); int R = (imgC >> ...
- 学习速率过大 or 过小
- Linux----添加zabbix-agent
1.zabbxi-agent安装及配置 1.1 获取官方zabbix源 [root@localhost ~]# rpm -ivh http://repo.zabbix.com/zabbix/3.4/r ...
- Parse发布Bolts,一个面向iOS和Android的底层库集合
转载自:http://www.infoq.com/cn/news/2014/02/parse-announces-bolts 数月前,Parse被Facebook收购.最近,它开源了一个面向iOS和A ...