The aspect oriented programming makes it possible to introduce additional code to an existing business logic. Because of that it simplified the implementation of cross-cutting concerns.
Spring AOP provides an easy way to realize the aspect oriented paradigma. What are cross-cutting concerns in detail or in which cases aspect oriented programming helps you to implement cross-cutting concerns?
Few examples:
- Logging
- Security
- Transaction management
- Locking
- Event handling
- Auditing
Example: MethodLoggingInterceptor
public class MethodLoggingInterceptor implements MethodInterceptor {
public Object invoke(MethodInvocation method) throws Throwable {
String classMethodIdentifier = method.getMethod().getDeclaringClass() + "." + method.getMethod().getName();
System.out.println(classMethodIdentifier + " starts");
Object result = method.proceed();
System.out.println(classMethodIdentifier + " finished");
return result;
}
}
aop-sample-ctx.xml
<bean name="methodLoggingInterceptor" class="org.developers.blog.spring.aop.logging.MethodLoggingInterceptor"/>
<bean name="proxyCreator" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="beanNames">
<list>
<value>*Manager</value>
<value>*Bean</value>
<value>*VO</value>
</list>
</property>
<property name="interceptorNames">
<list>
<value>methodLoggingInterceptor</value>
</list>
</property>
</bean>
RegardsRafael Sobek
Technorati Tags: Spring AOP AOP MethodInterceptor Proxy BeanNameAutoProxyCreator


good article.......
want to learn Logging using AOP (advice /pointcut)
u can find it here http://velmurugan-pousel.blogspot.com