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 ...
随机推荐
- less的编译
less其实也文本类型,跟txt的性质差不多 less有自己语法(变量,函数,作用域.Mixin混入),使css样式更加方便,有逻辑性,提高可维护性,减少重复性代码的冗余. 把less编译成css文件 ...
- 使用css完成物流进度的样式
使用css完成物流进度的样式 效果: css样式: <style type="text/css"> ul li { list-style: none; } .packa ...
- 服务器远程连接mysql问题解决
一. centos下解决远程连接不上的问题. 1.查看centos 下防火墙是否关闭: 通过进程: ps -aux |grep firewalld ps -ef |grep firewalld 通过服 ...
- 【ElasticSearch故障处理】OpenJDK 64-Bit Server VM warning
[故障描述] VM虚拟机安装ElasticSearch集群,有三台Linux,完成安装后,执行启动命令:bin/elasticsearch -d . 运行结果报错: OpenJDK 64-Bit Se ...
- Python学习之——Python安装
环境:Centos6.5+python2.7.5 1.centons6.5系统中是已经安装了python的,先查看版本是不是需要的 python --version 2.安装一些必要的包,防止后面需要 ...
- ubuntu 和windows 分别在anaconda上安装tensorflow
windows下 的anaconda安装tensorflow: 在Anaconda Prompt中:conda install tensorflow python=3.5一直下载失败.总结一下原因可能 ...
- hash环/consistent hashing一致性哈希算法
一致性哈希算法在1997年由麻省理工学院提出的一种分布式哈希(DHT)实现算法,设计目标是为了解决因特网中的热点(Hot spot)问题,初衷和CARP十分类似.一致性哈希修正了CARP使用的 ...
- Oracle Data Provider for .NET Support for Microsoft .NET Core
Oracle Data Provider for .NET Support for Microsoft .NET Core的官方地址,记录下来,按照官方描述,会在2017年底左右发布,暂时还没有看到相 ...
- 20155206 2016-2017-2 《Java程序设计》第1周学习总结
20155206 2016-2017-2 <Java程序设计>第1周学习总结 第一,二章学习内容总结 第一章 java基本知识 Java的三种技术架构: JAVAEE:Java Platf ...
- 20155302 2016-2017-2 《Java程序设计》第十周学习总结
20155302 2016-2017-2 <Java程序设计>第十周学习总结 教材学习内容总结 网络编程的实质就是两个(或多个)设备(例如计算机)之间的数据传输. 网络最主要的优势在于共享 ...