Aspect oriented programming (AOP) enables you to write code for a crosscutting functionality and then apply it declaratively to existing code. Logging is a prime candidate for implementation as an aspect, and Spring offers the AOP framework to get it done.
Spring AOP is implemented in pure java and only supports method execution join points. Spring AOP implementation uses a standard AOP API from the AOP Alliance. Spring AOP framework provides a close integration with Spring IOC container, aspects are configured using usual bean definition syntax, and uses Java dynamic proxies for AOP proxies, enabling any interface or set of interfaces to be proxied. Spring also supports integration with other popular AOP frameworks like AspectJ.
Spring's 'built-in' AOP infrastructure is defined by the org.springframework.aop.* packages.
Aspect - Think of this as the general feature you want to apply globally to your application (logging, performance monitoring, exception handling, transaction management, etc).
Advice - A chunk of code that is invoked during program execution, and is a piece of the logic for implementing your aspect. This is the first important piece of a Spring AOP aspect implementation! I like to compare advice implementations to the decorator pattern. While an advice doesn't necessarily wrap an entire object in concept, it has the same general effect. We'll learn in a bit that how that advice is applied is more granular/formal than typically defined in the decorator pattern however.
Joinpoint - A *single* location in the code where an advice should be executed (such as field access, method invocation , constructor invocation, etc.). Spring's built-in AOP only supports method invocation currently, so joinpoints aren't particularly important to focus on at this point.
Pointcut - A pointcut is a set of many joinpoints where an advice should be executed. So if, in Spring, a joinpoint is always a method invocation, then a pointcut is just a set of methods that, when called, should have advices invoked around them. This is the second important pieces of a Spring AOP aspect implementation!
Targets/Target Objects - The objects you want to apply an aspect or set of aspects to!
**The following example shows configuration of method level logging with spring AOP.
IBatis framework is a lightweight data mapping framework and persistence API that can be used to generate a database persistence layer for your Java application. A set of XML encoded SQL Map files–one for each database table–holds SQL templates that are executed as prepared statements and map the expected results to Java domain classes. From application code, a layer of iBatis Data Access Objects (DAO) acts as the API that executes the SQL Map templates and assigns the results to the corresponding Java domain classes.
The following code snippets will focus on integrating iBatis with Spring as well as getting data from database (using users_info table). We will use org.springframework.orm.ibatis.SqlMapClientFactoryBean class to integrate iBatis with spring.