ITeye博客

spring3.0 aspectj 的配置与使用

fantasy0707 · 2010-04-06 17:21 · 小学Spring · 企业架构 · Markdown

今天明白一点事,尝鲜是要花费代价的,想试下spring 3.0 的AOP,用aspecj做配置,一路上有太多的问题,真是麻烦,好在最后是成功了,这里再把要用到的Jar做个列表:

好多的jar文件要自己动手找下,要不就下载那个Spring3.0的依赖包吧, 里面会有想要的Jar不守100多M不是开玩笑,要用到的Jar见附件

测试代码:


package fantasy0707.spring.aop;

import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class LogInterceptor {
	
	@Pointcut("execution(public * fantasy0707.spring.service.*.*(..))")
	public void pointCut() {}
	
	@Before("pointCut()")
	public void before() {
		
		System.out.println("before method...");
		
	}

}


运行结果为:


2010-4-6 17:12:05 org.springframework.context.support.AbstractApplicationContext prepareRefresh
信息: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@cd5f8b: startup date [tue apr 06 17:12:05 cst 2010]; root of context hierarchy
2010-4-6 17:12:05 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
信息: Loading XML bean definitions from class path resource [beans.xml]
2010-4-6 17:12:06 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
信息: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@6210fb: defining beans [org.springframework.context.annotation.internalconfigurationannotationprocessor,org.springframework.context.annotation.internalautowiredannotationprocessor,org.springframework.context.annotation.internalrequiredannotationprocessor,org.springframework.context.annotation.internalcommonannotationprocessor,loginterceptor,userdao,service,org.springframework.aop.config.internalautoproxycreator]; root of factory hierarchy
init...
before method...
a user added!
2010-4-6 17:12:07 org.springframework.context.support.AbstractApplicationContext doClose
信息: Closing org.springframework.context.support.ClassPathXmlApplicationContext@cd5f8b: startup date [tue apr 06 17:12:05 cst 2010]; root of context hierarchy
2010-4-6 17:12:07 org.springframework.beans.factory.support.DefaultSingletonBeanRegistry destroySingletons
信息: Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@6210fb: defining beans [org.springframework.context.annotation.internalconfigurationannotationprocessor,org.springframework.context.annotation.internalautowiredannotationprocessor,org.springframework.context.annotation.internalrequiredannotationprocessor,org.springframework.context.annotation.internalcommonannotationprocessor,loginterceptor,userdao,service,org.springframework.aop.config.internalautoproxycreator]; root of factory hierarchy
destory...


评论(6)

  1. #6 楼 · 好事DOMO · 2012-10-11 20:33

    :idea: 对我很有用,支持!

  2. #5 楼 · jackywong · 2011-03-10 21:46

    beforezero writes:

    你好歹給個帶參數的啊

    public void afterMethod(JoinPoint jp){ Object args = jp.getArgs(); }

  3. #4 楼 · beforezero · 2011-03-10 17:51

    你好歹給個帶參數的啊

  4. #3 楼 · hellboyss · 2010-12-21 18:10

    今天弄了一下午 还是真的缺少这些JAR 太感谢了 就是不知道为什么 spring3里面会少这些

  5. #2 楼 · wei495715356 · 2010-04-08 14:35

    先支持你哈!

  6. #1 楼 · xiaokk · 2010-04-06 18:30

    老鸟们不看这个,新手我来顶你。

评论功能维护中,当前仅展示历史评论。