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. Connect(bzoj 1948)

    Description 给定一个R*C大小的迷宫,其中R,C均为奇数 迷宫中坐标为两个奇数的点不能通过,称为障碍,迷宫中其他不能通过的点统称为墙壁 坐标为两个偶数的点可以通过,称为房间,迷宫中其他可通 ...

  2. .net反编译工具Reflector下载(转)

    原文发布时间为:2010-10-23 -- 来源于本人的百度文章 [由搬家工具导入] 打开Reflector工具并且下载了一个FileDisassembler插件,FileDisassembler插件 ...

  3. VIM使用技巧4

    使移动和修改都能重复,对重复的操作能够回退比能够重复更加重要: 目的操作重复回退序号 执行修改{edit}.u1 在行内查找下一个指定字符 f{char}/t{char};,2 在行内查找上一个指定字 ...

  4. Python 函数的一般形式及参数

    #!/usr/bin/env python # -*- coding:utf-8 -*- # @Time : 2017/11/01 21:46 # @Author : lijunjiang # @Fi ...

  5. hadoop(二)hadoop的安装部署

    系统版本 : 64位CentOS6.6 hadoop版本: 1.2.1 jdk版本: jdk1.6.0_45 环境准备 1.主机分配 主机名 ip master 1.0.0.0.10 slave1 1 ...

  6. 转载——Visiual Studio2012 CLR20r3问题

    看到有更新,习惯性的点了,升级到Visiual Studio Ultimate 2012 Update 1,并且按照提升重启了电脑.因为昨天太晚,也没验证.尽早打开VS,结果直接Crash.错误如下: ...

  7. (5)centos图形界面安装

    1.登录 2.先安装MATE可视化桌面 yum groups install "MATE Desktop" 选择y 3.安装X Window System:图形接口 yum gro ...

  8. usaco-Money Systems

    题意: 给出几种硬币,求可用这几种硬币组合出价值为n的方案数.分析: 设dp[i]表示组合出价值i的方案数,则,dp[i]=∑dp[i-val[j]]. #include <iostream&g ...

  9. 暂停时间 以及dict 循环

    暂停时间 #!/usr/bin/python # -*- coding: UTF-8 -*- import time myD = {1: 'a', 2: 'b'} for key, value in ...

  10. Swagger2接口注释参数使用数组

    allowMultiple = true, paramType = "query", dataType = "string" 输出的就是这样的:Array[st ...