AOP:Spring的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: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配置方式的更多相关文章
- 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 基于xml配置方式的事务
参考前面的声明式事务的例子:http://www.cnblogs.com/caoyc/p/5632198.html 我们做了相应的修改.在dao中和service中的各个类中,去掉所有注解标签.然后为 ...
- spring 5.x 系列第21篇 —— spring 定时任务 (xml配置方式)
源码Gitub地址:https://github.com/heibaiying/spring-samples-for-all 一.说明 1.1 项目结构说明 关于任务的调度配置定义在springApp ...
- Spring 基于xml配置方式的事务(14)
参考前面的声明式事务的例子:http://www.cnblogs.com/caoyc/p/5632198.html 我们做了相应的修改.在dao中和service中的各个类中,去掉所有注解标签.然后为 ...
- spring中xml配置方式和注解annoation方式(包括@autowired和@resource)的区别
xml文件中配置itemSqlParameterSourceProvider是可以的: <bean id="billDbWriter" class="com.aa. ...
- Spring之AOP原理、代码、使用详解(XML配置方式)
Spring 的两大核心,一是IOC,另一个是AOP,本博客从原理.AOP代码以及AOP使用三个方向来讲AOP.先给出一张AOP相关的结构图,可以放大查看. 一.Spring AOP 接口设计 1.P ...
- Spring AOP源码分析(二):AOP的三种配置方式与内部解析实现
AOP配置 在应用代码中,可以通过在spring的XML配置文件applicationContext.xml或者基于注解方式来配置AOP.AOP配置的核心元素为:pointcut,advisor,as ...
- Spring Aop实例之xml配置
AOP的配置方式有2种方式:xml配置和AspectJ注解方式.今天我们就来实践一下xml配置方式. 我采用的jdk代理,所以首先将接口和实现类代码附上 package com.tgb.aop; pu ...
随机推荐
- JavaScript入门学习(1)
<html> <script type ="text/javascript"> var i,j; for (i=1;i<10;i++){ for (j ...
- MySQL数据库删除数据(有外键约束)
在MySQL中删除一张表或一条数据的时候,出现有外键约束的问题,于是就去查了下方法: SELECT @@FOREIGN_KEY_CHECKS; 查询当前外键约束是否打开 ; 设置为1的时候外键约束是打 ...
- ubuntu18.04 校准时间
运行如下命令: sudo tzselect 然后选择亚洲Asia,继续选择中国China,最后选择北京Beijing. 然后创建时区软链 sudo ln -sf /usr/share/zoneinfo ...
- Python之路(四)--->list、元组、字典
好久没有更新了,感觉自己写的东西并没有太多人看,可能是因为写的不好,也可能是太基础了.学习是一个漫长的过程,结果结果固然重要,但是更重要的是在学习的过程中所学到方法,这些方法在以后的生活还是工作中都能 ...
- 20155316 2016-2017-2 《Java程序设计》第1周学习总结
学习内容总结 在linux的环境下学习怎么安git.jdk.Intellj IDEA 精读教材1.2章 课前准备部分 git的学习 学习进度 系统学习学到创建版本库-廖雪峰的官方网站 git推送学到最 ...
- 微信小程序标签页切换
WXML中: <view class="swiper-tab"> <view class="swiper-tab-list {{currentTab== ...
- C#基础之反射
虽然还在学校读书,反射实际写的不多.但感觉反射在程序开发中用得还是挺多的,对我来说也是.NET中的一个难点.通过反射,我们可以在运行时获得.NET中的每一个类型的成员,这些类型包括类.结构.委托和枚举 ...
- [flex 布局]——flex教程
简介:2009年,W3C提出了一种新的方案----Flex布局,可以简便.完整.响应式地实现各种页面布局.目前,它已经得到了所有浏览器的支持,这意味着,现在就能很安全地使用这项功能. Flex布局是什 ...
- python-模块详解
模块: 模块的分类: 第三方模块/扩展模块:没在安装python解释器的时候安装的那些功能 自定义模块:你写的功能如果是一个通用的功能,那你就把它当做一个模块 内置模块:安装python解释器的时候跟 ...
- linux下汇编语言开发总结
汇编语言是直接对应系统指令集的低级语言,在语言越来越抽象的今天,汇编语言并不像高级语言那样使用广泛,仅仅在驱动程序,嵌入式系统等对性能要求苛刻的领域才能见到它们的身影.但是这并不表示汇编语言就已经没有 ...