<?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:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd"> <bean name="userManager" class="com.wangcf.manager.UserManagerImp"/>
<bean name="logManager" class="com.wangcf.manager.aspect.LogManager"/> <aop:config>
<aop:aspect id="logMgrAspect" ref="logManager">
<aop:before method="addLogBefore" pointcut="execution(* com.wangcf.manager.*.add*(..))"/>
<aop:after method="addLogAfter" pointcut="execution(* com.wangcf.manager.*.add*(..))"/>
</aop:aspect>
</aop:config>
</beans>
//切面类
package com.wangcf.manager.aspect; import org.aspectj.lang.JoinPoint; public class LogManager { public static void addLogBefore(){
System.out.println("添加日志 Before...");
} public void addLogAfter(){
System.out.println("添加日志记录 After...");
} public void addLogAfterReturning(){
System.out.println("添加日志记录 AfterReturning...");
} public void addLogAfterThrowing(){
System.out.println("添加日志记录 AfterThrowing...");
} public void addLogAround(JoinPoint joinPoint){
System.out.println("添加日志记录 AfterAround start...");
System.out.println(joinPoint.getTarget());
System.out.println("添加日志记录 AfterAround end...");
}
}

测试类:

package com.wangcf.test;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext; import com.wangcf.manager.IUserManager;
import com.wangcf.po.User; public class TestAction {
public static void main(String[] args) {
BeanFactory factory=new ClassPathXmlApplicationContext("applicationContext.xml");
IUserManager userManager=(IUserManager) factory.getBean("userManager");
//输出代理
System.out.println(userManager.getClass().getName());
userManager.addUser();
System.out.println("=================");
}
}

输出:

AOP:Spring的xml配置方式的更多相关文章

  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 基于xml配置方式的事务

    参考前面的声明式事务的例子:http://www.cnblogs.com/caoyc/p/5632198.html 我们做了相应的修改.在dao中和service中的各个类中,去掉所有注解标签.然后为 ...

  4. spring 5.x 系列第21篇 —— spring 定时任务 (xml配置方式)

    源码Gitub地址:https://github.com/heibaiying/spring-samples-for-all 一.说明 1.1 项目结构说明 关于任务的调度配置定义在springApp ...

  5. Spring 基于xml配置方式的事务(14)

    参考前面的声明式事务的例子:http://www.cnblogs.com/caoyc/p/5632198.html 我们做了相应的修改.在dao中和service中的各个类中,去掉所有注解标签.然后为 ...

  6. spring中xml配置方式和注解annoation方式(包括@autowired和@resource)的区别

    xml文件中配置itemSqlParameterSourceProvider是可以的: <bean id="billDbWriter" class="com.aa. ...

  7. Spring之AOP原理、代码、使用详解(XML配置方式)

    Spring 的两大核心,一是IOC,另一个是AOP,本博客从原理.AOP代码以及AOP使用三个方向来讲AOP.先给出一张AOP相关的结构图,可以放大查看. 一.Spring AOP 接口设计 1.P ...

  8. Spring AOP源码分析(二):AOP的三种配置方式与内部解析实现

    AOP配置 在应用代码中,可以通过在spring的XML配置文件applicationContext.xml或者基于注解方式来配置AOP.AOP配置的核心元素为:pointcut,advisor,as ...

  9. Spring Aop实例之xml配置

    AOP的配置方式有2种方式:xml配置和AspectJ注解方式.今天我们就来实践一下xml配置方式. 我采用的jdk代理,所以首先将接口和实现类代码附上 package com.tgb.aop; pu ...

随机推荐

  1. VS2017 编译 QT5.10.1 X64位 静态库 MT

    参考文章 https://blog.csdn.net/Devout_programming/article/details/78827112 准备工作* Supported compiler (Vis ...

  2. 在js中获取页面元素的属性值时,弱类型导致的诡异事件踩坑记录,

    前几天写一个js的时候遇到一个非常诡异的事情,这个问题是这样的,我要获取一个页面的DOM元素的val值,判断这个值是否比某个变量大,这个需求原先数字最大也就是10,现在要改了,可能会更多,这个时候我发 ...

  3. php设置文件类型content-type

    在PHP中可以通过header函数来发送头信息,还可以设置文件的content-type,下面整理了一些常见文件类型对于的content-type值. //date 2015-06-22//定义编码h ...

  4. 【七】ab压测

    [任务7]ab压测 安装ab压测软件 命令:yum -y install httpd-tools 进行压力测试: 执行命令:ab -c 20 -n 5000 http://192.168.159.30 ...

  5. 第一篇 C/C++基本语言类型

    总概: { C:面向过程,以过程为中心,以算法为驱动 } { C++:面向对象,以过对象中心,以消息为驱动 个人理解:一切皆对象的思想 } 一 前言总概 1.常量变量 初始化对象与赋值是两个概念 直接 ...

  6. MFC 中的 Value 和 Control

    一.變量類型不同:control 型变量是这个控件所属类的一个实例(对象),控制對象的變量.即變量代表對象本身.代表這個人!value 是用来传递数据,不能对控件进行其它的操作.向變量傳遞數據.代表這 ...

  7. stm32 IO口八种模式区别

    初学STM32,遇到I/O口八种模式的介绍,网上查了一下资料,下面简明写出这几种模式的区别,有不对的地方请大家多多指正! 上拉输入模式:区别在于没有输入信号的时候默认输入高电平(因为有弱上拉).下拉输 ...

  8. Google protobuf使用技巧和经验

    Google protobuf是非常出色的开源工具,在项目中可以用它来作为服务间数据交互的接口,例如rpc服务.数据文件传输等.protobuf为proto文件中定义的对象提供了标准的序列化和反序列化 ...

  9. windows server dump文件

    1. mini dump: ***** 需要包含 dbghelp.dll 库 ****mini_dump.h文件: // reference:https://msdn.microsoft.com/zh ...

  10. ASP.NET Web Form 与 ASP.NET MVC 区别

    Asp.net 微软提供web开发框架或者技术.分Web Form和ASP.NET MVC.下面简单说明各自优缺点及使用场景. Web Form ASP.NET Webform提供了一个类似于winf ...