`
thinktothings
  • 浏览: 766727 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

spring aop

阅读更多

http://xiebaolong.iteye.com/blog/653070

 

spring aop

 

 

package com.tht.aop.inter.imp;

import org.springframework.stereotype.Component;

/**
 * 刘文        Email:thinktothings@139.com
 * 2012-12-18 上午10:57:13
 */
@Component
public class SuperMan {
	
	public void readBook(String name) {
		System.out.println("读:"+name);

	}

}
 

 

 

package com.tht.aop.proxy;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;

/**
 * 刘文        Email:thinktothings@139.com
 * 2012-12-18 上午10:27:02
 */
@Aspect 
public class PersonProxy {

	
	@Pointcut("execution(public * *.*(..))")
	public void aPointcut(){
		
	}
    @After("aPointcut()") //定义切点,匹配规则为(范围 返回类型 返回类.方法(参数设置)    
    public void after(){    
        System.out.println("After:....................");    
    }  
      
    @Before("aPointcut()") //定义切点,匹配规则为(返回类型 方法(参数设置)  
    public void before(){    
        System.out.println("Before:*******************");    
    }  
    

}

 

 

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: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-3.0.xsd    
           http://www.springframework.org/schema/context    
           http://www.springframework.org/schema/context/spring-context-3.0.xsd    
           http://www.springframework.org/schema/aop    
           http://www.springframework.org/schema/aop/spring-aop-3.0.xsd    
           ">    
    <!-- 注册aspectj -->  
    <aop:aspectj-autoproxy/>  
      
    <!-- 注册代理过滤器 -->  
    <context:component-scan base-package="com.tht.aop">    
        <context:include-filter type="annotation"    
           expression="org.aspectj.lang.annotation.Aspect" />    
    </context:component-scan>  
      
<!--     <bean id="PersonProxy" class="com.baobao.aop.proxy.PersonProxy"/>     -->
<!--     <bean id="Man" class="com.baobao.aop.inter.imp.Man"/>     -->
</beans>  
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics