The introduction of Spring Aop

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)

Here Insert Picture Description

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.

Here Insert Picture Description
Here Insert Picture Description
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.
Here Insert Picture Description

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.

Here Insert Picture Description

Here Insert Picture Description
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).
Here Insert Picture Description

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)
Here Insert Picture Description
Here Insert Picture Description

Here Insert Picture Description

Based on the aop xml

Here Insert Picture Description

Published 74 original articles · won praise 2 · Views 6448

Guess you like

Origin blog.csdn.net/weixin_42067668/article/details/105151588