Introduction Why A Aop,
in our previous research, adding a transfer function, need to open a total of five transactions, this transaction will have five database using jdbc technology (Step 1 Create link 2, link database 3 prepare the database to perform the statement, 4, started, 5, 6 returns the result, the result of processing 7, the release link)
But if the middle of an exception occurs, it will cause abnormal before the transaction is successful, the transaction failed after the abnormal, the fundamental reason is that this transfer business should be written in the same unification of thread, a link is created by a thread, this global maintenance a database link, the five transactions to a unified affairs in the past.
The problem now is that the code and its redundant, readability is not strong, the other methods of transaction processing method depends particularly strong, the other is in the xml configuration and load-dependent. You should need to find ways to simplify.
Way - Dynamic Proxy
Since these are all service interface, you can use the dynamic proxy based (JDK dynamic proxy technology) interface, the processing of the transaction is executed as part of the additional agents added to the agent.
Note that the bean injection xml, and the service is dynamic agent beanfactory class generated when later use specific call again, so that the service is to generate the bean factory method (Method beanfactory in) (i.e. in an annotated version of this method on the profile corresponding to the plus @bean).
Leaving the question is just based
now remaining question is how to simplify the xml file.
Spring AOP
joinPoint connection points (all methods are proxy object)
PointCut pointcut (the method is enhanced)