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 ...
随机推荐
- Linux基础练习题(五)
1.创建一个10G分区,并格式为ext4文件系统: (1) 要求其block大小为2048, 预留空间百分比为2, 卷标为MYDATA, 默认挂载属性包含acl: [root@bj-1-142 ~]# ...
- 【Linux】文件、目录权限及归属
访问权限: 可读(read):允许查看文件内容.显示目录列表 可写(write):允许修改文件内容,允许在目录中新建.移动.删除文件或子目录 可执行(execute):允许运行程序.切换目录 归属: ...
- 浅谈nodejs中HTTP模块应用
这里给大家分享下后端人员如果利用nodejs对数据的一些处理情况 适用于初学者使用 大牛勿喷 给大家分享下主要后端思想部分代码,前端部分就不展示了 const http = require(&quo ...
- swiper一组图片,点击图片出现中间,看效果
好兄弟先看看效果是这样的么 点击哪个头像,头像移动到中间,然后放大,demo上写了五条数据 废话不多说 直接上代码 1.引入swiper.css, swiper.js 2.HTML(小弟做的是移动端的 ...
- Iframe 定义内联的子窗口(框架)
1.Iframe 定义内联的子窗口(框架),用于在网页内显示网页 语法: <iframe src="URL"></iframe>URL 指向隔离页面的位置, ...
- PHP的strtotime()函数2038年bug问题
最近在开发一个订单查询模块的时候,想当然的写了个2099年的日期,结果PHP返回了空值,肯定是发生溢出错误了,搜索了网上,发现下面这篇文章,但是我的问题依然没有解决,要怎么得到2038年以后的时间戳呢 ...
- nginx 开启phpinfo
在nginx配置文件中加 location / { //如果是资源文件,则不走phpinfo模式 if (!-e $request_filename){ ewrite ^/(.*)$ /index.p ...
- colemak,你用了吗?
为了输入代码的感觉更好,我学习了colemak键盘布局,这个布局它是在QWERTY的基础上改了10多个键. 开始的三天,感觉非常不好,每按一个键都要思考很长时间,干脆在网上找了个在线打字的网页去练,感 ...
- centos7 关闭防火墙
centos7 关闭防火墙 1.firewall相关的操作 查看防火墙状态 firewall-cmd --state 关闭防火墙 systemctl stop firewalld.s ...
- Hadoop分布式集群搭建_1
Hadoop是一个开源的分布式系统框架 一.集群准备 1. 三台虚拟机,操作系统Centos7,三台主机名分别为k1,k2,k3,NAT模式 2.节点分布 k1: NameNode DataNode ...