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的更多相关文章

  1. springmvc aop 事务配置

    对应的中文: 任意公共方法的执行: execution(public * *(..)) 任何一个以“set”开始的方法的执行: execution(* set*(..)) AccountService ...

  2. spring(一)--spring/springmvc/spring+hibernate(mybatis)配置文件

    这篇文章用来总结一下spring,springmvc,spring+mybatis,spring+hibernate的配置文件 1.web.xml 要使用spring,必须在web.xml中定义分发器 ...

  3. 任务调度--spring下的任务调度quartz

    之前写过Timer实现任务调度,这篇文章用来写一下在spring下使用quartz实现任务调度,直接上代码: 定义任务对象: package com; /** * 1. 定义任务对象 * * @aut ...

  4. springMVC Aspect AOP 接口耗时统计

    在接口开发中,我们通常需要统计接口耗时,为后续接口性能做统计.在springMVC中可以用它的aop来记录日志. 1.在spring配置文件中开启AOP <!--*************** ...

  5. SpringMVC集成AOP错误:java lang classnotfoundexception org aspectj lang joinpoint

    记录自己出现的问题,Spring AOP 使用测试类测试没问题,在SpringMVC启动服务器时出现java lang classnotfoundexception org aspectj lang ...

  6. springMVC+MyBatis+Spring 整合(4) ---解决Spring MVC 对AOP不起作用的问题

    解决Spring MVC 对AOP不起作用的问题 分类: SpringMVC3x+Spring3x+MyBatis3x myibaits spring J2EE2013-11-21 11:22 640 ...

  7. springmvc集成aop记录操作日志

    首先说明一下,这篇文章只做了记录日志相关事宜 具体springmvc如何集成配置aop对cotroller进行拦截,请看作者的另一篇文章 http://www.cnblogs.com/guokai87 ...

  8. springmvc配置aop

    直接看代码 springmvc中的配置aop对 controller和它的子包进行拦截 springmvc中的配置 <!--xml头部配置需要有这几行代码--> xmlns:aop=&qu ...

  9. spring框架整合springMVC时关于AOP无法切入的问题

    最开始springMVC的配置为: spring的配置为: 分析可知道spring的配置正确,由于在springmvc中已经扫描了@Controller相关的注解,所以就不需要再次扫描了,由于spri ...

随机推荐

  1. Bits

    先%SY... 课件链接 求1的个数 以32位整数为例子,最暴力的方法就是一位一位的数,但是这样太不优美... 以下是优美的方法... 这个问题其实就是二进制求和... 我们考虑分治的思想...每一次 ...

  2. 常用“Request.ServerVariables()”汇总

    原文发布时间为:2009-10-25 -- 来源于本人的百度文章 [由搬家工具导入] Request.ServerVariables("REMOTE_ADDR")         ...

  3. FCKeditor2.6.4控件及其使用范例

    原文发布时间为:2009-06-14 -- 来源于本人的百度文章 [由搬家工具导入] 已经精简了,很小,不多说了,我的源代码去下载看。 web.config 看看。。。还有bin里面的dll就是控件, ...

  4. 使用C#的BitmapData

    原文发布时间为:2009-01-16 -- 来源于本人的百度文章 [由搬家工具导入] 我在前两篇图片处理的文章里几乎都用BitmapData来做图片处理的,那么这个东东究竟是个什么玩意儿呢? C#好是 ...

  5. 《Linux命令行与shell脚本编程大全 第3版》Linux命令行---31

    以下为阅读<Linux命令行与shell脚本编程大全 第3版>的读书笔记,为了方便记录,特地与书的内容保持同步,特意做成一节一次随笔,特记录如下:

  6. VIM使用技巧5

    查找并手动替换.例如有如下一段文字: We' re waiting for content before the site can go live If you are content with th ...

  7. linux内核情景分析之命名管道

    管道是一种"无名","无形文件,只可以近亲进程使用,不可以再任意两个进程通信使用,所以只能实现"有名","有形"的文件来实现就可以 ...

  8. 開關(switch)規格中,SPDT, DPDT, 3PDT, 4PDT是什麼意思?

    Reference http://blog.xuite.net/auster.lai/twblog/433393966 開關(switch)用來控制電路的開與閉,機械式的switc內部是由接點開關.彈 ...

  9. LeetCode OJ-- Divide Two Integers *

    https://oj.leetcode.com/problems/divide-two-integers/ 在不使用乘法.除法.求余的情况下计算除法. 使用减法计算,看看减几次. 刚开始寻思朴素的暴力 ...

  10. Jquery 返回json数据在IE浏览器中提示下载的问题

    Jquery 返回json数据,IE浏览器提示下载的问题,当提交完数据后返回的本来是json数据的,在火弧里测试正常,解决方法如下 今天遇到Jquery 返回json数据,IE浏览器提示下载的问题,当 ...