您的位置:首页 > 运维架构

基于注释的AOP的一个配置文件!

2010-07-29 21:47 344 查看
1.一个辅助功能类

package com.semi;

import java.lang.reflect.Method;

import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.aop.MethodBeforeAdvice;
import org.springframework.stereotype.Component;
@Aspect
@Component("MySemi")
public class LogSemi implements Semi{
@Pointcut("execution(* com.Logic.FirstMethod.add(..))")
public void my(){
}
@Before("com.semi.LogSemi.my()")
//@After("com.semi.LogSemi.my()")
public void print() {
System.out.println("Log has been written!");
}
}


2.配置文件

<?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:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd" >
<context:component-scan base-package="com.*"/>
<aop:aspectj-autoproxy/>

</beans>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: