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 ...
随机推荐
- 20181031noip模拟赛T2
思路: 这道题是个图论抽象的题目…… 考场上想到了没写对…… 我们发现,f函数转移的方式有两种,要么是代价10的+1,要么是代价1的乘一个质因数 那么我们就可以将这个抽象为一张图 每个i向每个i+1连 ...
- LL(1)文法--递归下降程序
递归下降程序 递归下降程序一般是针对某一个文法的.而递归下降的预测分析是为每一个非终结符号写一个分析过程,由于文法本身是递归的,所以这些过程也是递归的. 以上是前提. Sample 假如给的是正规式子 ...
- python的requests模块爬取网页内容
注意:处理需要用户名密码认证的网站,需要auth字段. # -*- coding:utf-8 -*- import requests headers = { "User-Agent" ...
- linux重要目录
1.网卡配置文件 /etc/sysconfig/network-scripts/ifcfg-eth* 2.客户端dns配置文件 /etc/resolv.conf 网卡配置文件中的dns配置优先于此文件 ...
- Leetcode---栈系列刷题(python3实现)----#20有效的括号
给定一个只包括 '(',')','{','}','[',']' 的字符串,判断字符串是否有效. 有效字符串需满足: 左括号必须用相同类型的右括号闭合. 左括号必须以正确的顺序闭合. 注意空字符串可被认 ...
- Python-dataframe合并(merge函数)
import pandas as pd import numpy as np df1=pd.DataFrame({'key':['b','b','a','c','a','a','b'],'data1' ...
- java的三个体系
Java是由SunMicrosystems公司于1995年5月推出的Java面向对象程序设计语言和Java平台的总称.由JamesGosling和同事们共同研发,并在1995年正式推出. Java分为 ...
- 20155213 实验一《Java开发环境的熟悉》实验报告
20155213 实验一<Java开发环境的熟悉>实验报告 一. 实验内容及步骤 (一)使用JDK编译.运行简单的java程序 命令行下的程序开发 输入cd Code进入Code文件夹里 ...
- 20155217 2016-2017-2 《Java程序设计》第10周学习总结
20155217 2016-2017-2 <Java程序设计>第10周学习总结 教材学习内容总结 网络编程 网络编程就是在两个或两个以上的设备(例如计算机)之间传输数据. 程序员所作的事情 ...
- 随笔三 安装Linux操作系统
一.虚拟机安装Ubuntu图文教程]在自己笔记本上安装Linux操作系统 我参考了VirtualBox虚拟机安装Ubuntu的图文教程,根据图片和所附内容一步步的将虚拟机安装到位,没看安装教程之前完全 ...