spring2.0 配置AOP(切面)
来源:互联网 发布:如何注册淘宝小号安全 编辑:程序博客网 时间:2024/06/03 00:25
第一,修改Spring的配置文件applicationContext.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"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
第二,添加AOP定义
<!-- ***************************AOP的定义begin***********************************-->
<!-- 自定义Aspect -->
<bean id="logBeforeAdvice" class="com.accp.util.MyLogger" />
<aop:config>
<aop:aspect id="logging" ref="logBeforeAdvice"><!-- 前置 -->
<aop:before method="before"
pointcut="execution(* com.accp.service.*.*(..))" />
<aop:after-returning method="afterReturning"
pointcut="execution(* com.accp.service.*.*(..))" /><!-- 后置 -->
<aop:after-throwing pointcut="execution(* com.accp.service.*.*(..))"
throwing="throwable" method="afterThrowing" />
</aop:aspect>
</aop:config>
<!--***************************AOP的定义end***********************************-->
第三,使用代码
package com.accp.util;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.lang.reflect.Method;
import org.aspectj.lang.JoinPoint;
import org.springframework.aop.MethodBeforeAdvice;
public class MyLogger {
private Logger logger = Logger.getLogger(this.getClass().getName());
public void before(JoinPoint jointPoint) throws Throwable {
// System.out.println("--------------begin-------------");
logger.log(Level.INFO, "<<<<<method starts..."
+ jointPoint.getSignature().getDeclaringTypeName() + "."
+ jointPoint.getSignature().getName() + ">>>>>>");
}
public void afterReturning(JoinPoint jointPoint) {
// System.out.println("-------------end-----------------");
logger.log(Level.INFO, "<<<<<method ends..."
+ jointPoint.getSignature().getDeclaringTypeName() + "."
+ jointPoint.getSignature().getName() + ">>>>>>");
}
}
- spring2.0 配置AOP(切面)
- spring2.0 aop配置
- Spring2.0 AOP @AspectJ注解定义切面学习示例。
- Spring框架-AOP细节2(XML配置AOP切面)
- Spring AOP学习笔记(4):AOP切面优先级&切面表达式重用&xml配置方式
- Spring AOP使用配置介绍(二):切面的配置
- spring2.0和AOP
- spring2.0和AOP
- Spring2.0 AOP 随笔
- spring2.0 AOP
- AOP面向切面编程配置
- spring-aop配置多切面
- 面向切面(AOP)
- 切面编程(AOP)
- Spring配置过程 (二)面向切面编程AOP
- Spring2.0 AOP 的实现
- aop实现-spring2.0中的aop实现
- Spring3.0 学习-AOP面向切面编程_Spring AOP的XML配置模式
- 夕阳
- 豆瓣差评新记录
- .NET、ASP.NET控件及源码大汇总
- Spring事务解惑
- fsck解决Linux数据丢失问题
- spring2.0 配置AOP(切面)
- 流程图编辑控件
- InstallShield在卸载的时候将安装时生成的安装文件及dll也删除
- MFC消息映射的学习
- 百度产品经理探秘:需求把握和正确决策
- 创建者模式
- 调整输入法顺序
- 8 Puzzle/8 数码问题
- 11.5线程----同步装置之Exchanger