SpringMvc aop before
1.config.xml配置文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans> <bean id="logBefore" class="com.gc.action.LogBefore"></bean>
<bean id="timeBook" class="com.gc.action.TimeBook"></bean>
<bean id="logBeforeAdvisor" class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">
<!-- advice 要加入的代码 -->
<property name="advice">
<ref bean="logBefore"></ref>
</property> <!--指定do开头的方法 -->
<property name="patterns">
<value>.*do.*</value>
</property>
</bean> <!-- LogBefore -->
<bean id="logProxy1" class="org.springframework.aop.framework.ProxyFactoryBean">
<!-- 该配置也可以去掉 -->
<property name="proxyInterfaces">
<value>com.gc.action.ITimeBook</value>
</property> <!-- 被代理的对象 -->
<property name="target">
<ref bean="timeBook"></ref>
</property>
<!--引入代理配置 -->
<property name="interceptorNames">
<list>
<value>logBeforeAdvisor</value>
</list>
</property> </bean>
</beans>
2.LogBefore
package com.gc.action;
import java.lang.reflect.Method;
import org.springframework.aop.MethodBeforeAdvice;
public class LogBefore implements MethodBeforeAdvice{
@Override
public void before(Method arg0, Object[] arg1, Object arg2)
throws Throwable {
System.out.println("before aop 前");
// TODO Auto-generated method stub
}
}
3.ITimeBook
package com.gc.action;
public interface ITimeBook {
public void doAudit(String name);
}
4.TimeBook
package com.gc.action;
public class TimeBook implements ITimeBook {
@Override
public void doAudit(String name) {
// TODO Auto-generated method stub
System.out.println("laaaaaaaaaaaaa");
}
}
5.测试
ApplicationContext context=new FileSystemXmlApplicationContext("config-before.xml");
ITimeBook tb=(ITimeBook)context.getBean("logProxy1");
tb.doAudit("xiaox");
SpringMvc aop before的更多相关文章
- springmvc aop 事务配置
对应的中文: 任意公共方法的执行: execution(public * *(..)) 任何一个以“set”开始的方法的执行: execution(* set*(..)) AccountService ...
- spring(一)--spring/springmvc/spring+hibernate(mybatis)配置文件
这篇文章用来总结一下spring,springmvc,spring+mybatis,spring+hibernate的配置文件 1.web.xml 要使用spring,必须在web.xml中定义分发器 ...
- 任务调度--spring下的任务调度quartz
之前写过Timer实现任务调度,这篇文章用来写一下在spring下使用quartz实现任务调度,直接上代码: 定义任务对象: package com; /** * 1. 定义任务对象 * * @aut ...
- springMVC Aspect AOP 接口耗时统计
在接口开发中,我们通常需要统计接口耗时,为后续接口性能做统计.在springMVC中可以用它的aop来记录日志. 1.在spring配置文件中开启AOP <!--*************** ...
- SpringMVC集成AOP错误:java lang classnotfoundexception org aspectj lang joinpoint
记录自己出现的问题,Spring AOP 使用测试类测试没问题,在SpringMVC启动服务器时出现java lang classnotfoundexception org aspectj lang ...
- springMVC+MyBatis+Spring 整合(4) ---解决Spring MVC 对AOP不起作用的问题
解决Spring MVC 对AOP不起作用的问题 分类: SpringMVC3x+Spring3x+MyBatis3x myibaits spring J2EE2013-11-21 11:22 640 ...
- springmvc集成aop记录操作日志
首先说明一下,这篇文章只做了记录日志相关事宜 具体springmvc如何集成配置aop对cotroller进行拦截,请看作者的另一篇文章 http://www.cnblogs.com/guokai87 ...
- springmvc配置aop
直接看代码 springmvc中的配置aop对 controller和它的子包进行拦截 springmvc中的配置 <!--xml头部配置需要有这几行代码--> xmlns:aop=&qu ...
- spring框架整合springMVC时关于AOP无法切入的问题
最开始springMVC的配置为: spring的配置为: 分析可知道spring的配置正确,由于在springmvc中已经扫描了@Controller相关的注解,所以就不需要再次扫描了,由于spri ...
随机推荐
- Safari 11.0 已发布,新特性都在这儿了!
Safari 11.0 兼容性 Safari 11.0 可运行于 iOS 11.0 和 macOS 10.1版本的系统环境,同时在macOS 10.12.6 和 10.11.6版本中也可以使用. Hi ...
- 负载平衡(cogs 741)
«问题描述:G 公司有n 个沿铁路运输线环形排列的仓库,每个仓库存储的货物数量不等.如何用最少搬运量可以使n 个仓库的库存数量相同.搬运货物时,只能在相邻的仓库之间搬运.«编程任务:对于给定的n 个环 ...
- powershell 调用winform dll
//1.加载dll,调用winform窗体,使用指定构造函数 param{ $filePath="" } [void][reflection.assembly]::LoadFile ...
- a kind of async programming in c#, need to reference definition
void Main() { Run d=new Run(RunHandler); IAsyncResult result= d.BeginInvoke(new AsyncCallback(CallBa ...
- Zookeeper如何从官网下载和安装
打开百度搜索,输入Zookeeper关键词,一般第一条搜索记录就是apache官网下载的地址 进入apache官网,由于是国外的网站,里面内容都是英文的,可以大概看下Zookeeper的描述和介绍,在 ...
- 《Linux命令行与shell脚本编程大全 第3版》Linux命令行---54
以下为阅读<Linux命令行与shell脚本编程大全 第3版>的读书笔记,为了方便记录,特地与书的内容保持同步,特意做成一节一次随笔,特记录如下:
- 记Django数据库迁移过程中遇到的一些问题
首先描述一下问题,Django 数据库使用的mysql, 然后开始没注意,没建一个default库,就把第一个数据库当成默认的了,结果Django的admin相关的那些表,都自动生成到这个库里了,现在 ...
- Day 21 Object_oriented_programming_2
继承实现原理 python中的类可以同时继承多个父类,继承的顺序有两种:深度优先和广度优先. 一般来讲,经典类在多继承的情况下会按照深度优先的方式查找,新式类会按照广度优先的方式查找 示例解析: 没有 ...
- Linux常用命令使用
系统基础相关 使用root用户的环境变量切换到root用户 su - 显示当前工作路径 pwd 显示当前系统默认语言及键盘布局 localectl 显示系统中能支持的所有语言 localectl li ...
- ios textfield如何设置,只能输入1.0-9.9内的数字,并实现时时监测效果
//byzqk- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range repla ...