面向切面编程AOP:基于XML文件的配置
除了使用AspectJ注解声明切面,Spring也支持在bean的配置文件中声明切面,这种声明是通过aop scheme中的XML元素完成的。
首先建立一个类:
package com.sevenhu.AOPTests; import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Before; import java.util.Arrays; /**
* Created by hu on 2016/4/1.
*/
public class AspectDemo1 {
//前置通知
@Before("execution(public int com.sevenhu.AOPTests.Calculator.*(int ,int ))")
public void beforeMethod(JoinPoint joinPoint){
String methodName=joinPoint.getSignature().getName();
Object[] args=joinPoint.getArgs();
System.out.println("The method "+methodName+" begins with "+ Arrays.asList(args));
}
}
配置如下:
<!--使AspesctJ的注解起作用-->
<aop:aspectj-autoproxy></aop:aspectj-autoproxy>
<bean id="aspectDemo1" class="com.sevenhu.AOPTests.AspectDemo1"></bean>
<aop:config>
<aop:aspect id="aspect1" ref="aspectDemo1"></aop:aspect>
</aop:config>
基于XML声明切入点:
<!--使AspesctJ的注解起作用-->
<aop:aspectj-autoproxy></aop:aspectj-autoproxy>
<bean id="aspectDemo1" class="com.sevenhu.AOPTests.AspectDemo1"></bean>
<aop:config>
<aop:pointcut id="cutExpression" expression="execution(* *.*(..))"/>
<aop:aspect id="aspect1" ref="aspectDemo1"></aop:aspect>
</aop:config>
声明通知的示例代码:
<!--加入自动扫描的包-->
<context:component-scan base-package="com.sevenhu.AOPTests"></context:component-scan>
<!--使AspesctJ的注解起作用-->
<aop:aspectj-autoproxy></aop:aspectj-autoproxy>
<bean id="aspectDemo1" class="com.sevenhu.AOPTests.AspectDemo1"></bean>
<aop:config>
<aop:pointcut id="cutExpression" expression="execution(* *.*(..))"/>
<aop:aspect id="aspect1" ref="aspectDemo1">
<aop:before method="beforeMethod" pointcut-ref="cutExpression"></aop:before>
</aop:aspect>
</aop:config>
面向切面编程AOP:基于XML文件的配置的更多相关文章
- Spring学习手札(二)面向切面编程AOP
AOP理解 Aspect Oriented Program面向切面编程,通过预编译方式和运行期动态代理实现程序功能的统一维护的一种技术. 但是,这种说法有些片面,因为在软件工程中,AOP的价值体现的并 ...
- Spring学习笔记:面向切面编程AOP(Aspect Oriented Programming)
一.面向切面编程AOP 目标:让我们可以“专心做事”,避免繁杂重复的功能编码 原理:将复杂的需求分解出不同方面,将公共功能集中解决 *****所谓面向切面编程,是一种通过预编译方式和运行期动态代理实现 ...
- Spring框架学习笔记(2)——面向切面编程AOP
介绍 概念 面向切面编程AOP与面向对象编程OOP有所不同,AOP不是对OOP的替换,而是对OOP的一种补充,AOP增强了OOP. 假设我们有几个业务代码,都调用了某个方法,按照OOP的思想,我们就会 ...
- 04 Spring:01.Spring框架简介&&02.程序间耦合&&03.Spring的 IOC 和 DI&&08.面向切面编程 AOP&&10.Spring中事务控制
spring共四天 第一天:spring框架的概述以及spring中基于XML的IOC配置 第二天:spring中基于注解的IOC和ioc的案例 第三天:spring中的aop和基于XML以及注解的A ...
- Spring框架系列(4) - 深入浅出Spring核心之面向切面编程(AOP)
在Spring基础 - Spring简单例子引入Spring的核心中向你展示了AOP的基础含义,同时以此发散了一些AOP相关知识点; 本节将在此基础上进一步解读AOP的含义以及AOP的使用方式.@pd ...
- 设计模式之面向切面编程AOP
动态的将代码切入到指定的方法.指定位置上的编程思想就是面向切面的编程. 代码只有两种,一种是逻辑代码.另一种是非逻辑代码.逻辑代码就是实现功能的核心代码,非逻辑代码就是处理琐碎事务的代码,比如说获取连 ...
- Spring之控制反转——IoC、面向切面编程——AOP
控制反转——IoC 提出IoC的目的 为了解决对象之间的耦合度过高的问题,提出了IoC理论,用来实现对象之间的解耦. 什么是IoC IoC是Inversion of Control的缩写,译为控制 ...
- 【串线篇】面向切面编程AOP
面向切面编程AOP 描述:将某段代码“动态”的切入到“指定方法”的“指定位置”进行运行的一种编程方式 (其底层就是Java的动态代理)spring对其做了简化书写 场景: 1).AOP加日志保存到数据 ...
- [译]如何在ASP.NET Core中实现面向切面编程(AOP)
原文地址:ASPECT ORIENTED PROGRAMMING USING PROXIES IN ASP.NET CORE 原文作者:ZANID HAYTAM 译文地址:如何在ASP.NET Cor ...
- 面向切面编程AOP
本文的主要内容(AOP): 1.AOP面向切面编程的相关概念(思想.原理.相关术语) 2.AOP编程底层实现机制(动态代理机制:JDK代理.Cglib代理) 3.Spring的传统AOP编程的案例(计 ...
随机推荐
- 修改MyEclipse默认的Servlet和jsp代码模板
一.修改Servlet的默认模板代码 使用MyEclipse创建Servlet时,根据默认的Servlet模板生成的Servlet代码如下: 1 package gacl.servlet.study; ...
- docker es and es cluster
How to use this image You can run the default elasticsearch command simply: $ docker run -d elastics ...
- sqlserver 计算 百分比
,),))+'%' As 百分比 NUMERIC(P,S) P的默认值是:38 S的默认值是:-84~127 numeric(a,b)函数有两个参数,前面一个为总的位数,后面一个参数是小数点后的位数, ...
- RequestContextListener有什么用
问题: java.lang.IllegalStateException: No thread-bound request found: Are you referring to request att ...
- aspx后台页面添加服务器控件
System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder(); System.IO.StringWriter st ...
- Magento添加一个下拉登陆菜单Create Magento Dropdown Login in a few minutes
Dropdown login forms are not a feature many online stores use, but in some cases they could be quite ...
- Fiddler-008-简单模拟性能测试
通过 Fiddler 可以简单的模拟性能测试的并发测试,此方法非常的简单,直接讲述如何使用,敬请参阅! 首先我们要获取需要并发的 HTTP请求,此操作非常简单,则在此不再赘述.获取到响应的 HTTP请 ...
- win2008主机IIS7.x 关于web.config设置301重定向
win2008主机IIS7.x 关于web.config设置301重定向 要求:windows主机是IIS7.0或以上的版本 方法如下: 在网站的根目录下新建web.config文件并将一下代码加入到 ...
- tomcat启动出现PermGen space错误
今天部署项目时,出现了jvm内存溢出的问题,显示PermGen space错误. 经过不断的努力,终于解决出来了. 步骤如下: 在eclipse中菜单栏run-->RunConfigurati ...
- Could not find class XXX referenced from method XXX.<YYY>
Since some ADT-Version you have to set which libraries / projects should be exported too. Project-Pr ...