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 ...
随机推荐
- c语言中字符串转数字的函数
ANSI C 规范定义了 atof().atoi().atol().strtod().strtol().strtoul() 共6个可以将字符串转换为数字的函数,大家可以对比学习.另外在 C99 / C ...
- Backpack III
Description Given n kinds of items, and each kind of item has an infinite number available. The i-th ...
- python django -在setting 设定全局时间格式
工作中遇到需要全局设定时间的格式,再此马克下 USE_L10N = False DATE_FORMAT = 'Y-m-d' DATETIME_FORMAT = 'Y年m月'
- centos7.3 安装 mysql-5.7.13
系统环境: [root@localhost ~]# cat /etc/RedHat-release CentOS release 6.7 (Final)[root@localhost tools]# ...
- leetcode 712
这道题的思路:我是根据最长公共子序列的思路得来的. 最长公共子序列是: d[i][j]表示字符串s1前i个(0-i-1)字符,和字符串s2前j个(0-j-1)字符的最长公共子序列. 分情况讨论: 当s ...
- mysql group by order by havaing where 顺序
结论: select xx from xx where xx group by xx order by xxx; select xx from xx group by xx having xx ord ...
- avalon中的ms-attr?
<div class="item" id="move5" style="margin:0" > <a class=&quo ...
- 4、vueJs基础知识04
简单的目录结构: |-index.html |-main.js 入口文件 |-App.vue vue文件(组件),官方推荐命名法(首字母大写) |-components 组件存放的文件夹 | ...
- SignalR要求_转自:https://www.cnblogs.com/humble/p/3855137.html
SignalR 服务端组件可以被部署在诸多的服务器配置中,本节描述了它所支持的操作系统版本,.NET framework,IIS.以及其他组件 二.支持的服务器操作系统 SignalR服务端组件可以被 ...
- mysql命令行修改密码
1.以管理员身份打开cmd窗口2.进入安装mysql的bin目录.3.命令net start mysql开启服务4.mysql -u root -p 管理员登陆5.输入旧密码后进入数据库6.输入ALT ...