
Annotation Support in Spring AOP-1
Annotations have been introduced in Jdk1.5 (Tiger) release. This has changed the way we give deployment description of the components. Prior to annotation all the deployment description is given in XML files like we have seen <aop:config> tag in the previous examples. AspectJ annotations are the part of the AspectJ 5 release.
- <aop:aspectj-autoproxy/>
- <bean class="org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator" />
Example: -Lets take a logging example. Lets take an example of a banking application where we have account class. We have two methods in the class one is deposit and another one is withdrawal.
AccountService.java
package com.visualbuilder.aop; public interface AccountService { void deposit(double amount)throws Exception; void withdrawal(double amount)throws Exception; public double getBalance(); public void setBalance(double amount); } |
AccountServiceImpl.java
package com.visualbuilder.aop; public class AccountServiceImpl implements AccountService { private double balance=0; public void deposit(double amount) throws Exception{ if(amount >0){ balance=balance+amount; }else{ throw new Exception("invalid amount"); } } public void withdrawal(double amount)throws Exception { if(balance >0 && amount < balance){ balance=balance-amount; }else{ throw new Exception("insufficient balance"); } } public double getBalance() { return balance; } public void setBalance(double balance) { this.balance = balance; } } |
Java Discussion
- - Difference between BMT an
- - Replace getParameterValue
- - Interviewing Next week -
- - Sudoku solver
- - Setting tab order in swin



