<context:annotation-config /> <bean id="executionTimeLoggingSpringAop" class="big.ExecutionTimeLoggingSpringAOP" /> <aop:config> <aop:pointcut id="executionTimeLoggingPointcut" expression="execution(public * sayHello(..))" /> <aop:advisor id="executionTimeLoggingAdvisor" advice-ref="executionTimeLoggingSpringAop" pointcut-ref="executionTimeLoggingPointcut" /> </aop:config>
在上述代码中ExecutionTimeLoggingSpringAOP为实现了MethodBeforeAdvice, AfterReturningAdvice这两个接口的类,这两个接口分别是在目标方法执行前和后分别定义一个方法用于执行。aop:pointcut定义了切入点和表达式。aop:advisor用于将切入点和通知进行结合。spring
1.tips:在applicationcontext.getbean(returntype)获取spring上下文的bean,参数是须要返回的bean的类型,参数能够是超类或者接口,可是超类或者接口在spring上下文中的实现bean有且只有一个,若是没有抛出NoSuchBeanDefinitionException异常,若是由多个则抛出bean不惟一异常。在进行注解一个bean时,value值默认为空,bean的名称由类名或方法名代替,首写字母小写。express
2.切入点指示符,匹配表达式:类型签名表达式编程
<aop:pointcut id="executionTimeLoggingPointcut" expression="within(bean.*)" />
经过使用within能够指定接口,包名,类名类过滤方法。上述则指定了bean包名,将bean包中的全部方法都应用advice通知。app
3.使用方法签名表达式关键字executionxml
4.blog
<aop:aspectj-autoproxy />
这句代码在xml中进行配置,表示开启切面编程。接口
5.@aspect在一个类上使用,表示这个类具备aop功能。ip