In the Spring core framework, the two most critical mechanisms, ioc and AOP, instantiate all our beans according to XML configuration or annotations, manage dependency injection between beans, decouple classes from classes, and maintain code more easily and conveniently

Spring already manages all object instances of this class, beans, in our code

We have dozens of Service components, like the same code, duplicate code, and have to write the exact same thing in dozens of places

The Spring AOP mechanism is here to stay

He has several concepts, can make a section, grammar, usage, terminology and concept, complete, detailed understanding, the Internet to search for some information

Let’s make a section. How do we define it? MyServiceXXXX this class, in all methods of these classes, to weave some code, run in the beginning of all of these methods, first to open a transaction, in all of these methods after operation, to according to the judging whether an exception is thrown, if an exception is thrown, roll back the transaction, without exception, On committing transactions =› AOP

Aspect oriented programming

Based on Spring AOP, how to do aspects, how to define enhanced code, how to define which classes and which methods to enhance

When Spring runs, dynamic proxies, the core technology of AOP, are dynamic proxies

It will generate dynamic proxies for your classes

Transaction, mysql database, all provide a transaction mechanism, if we start a transaction, execute multiple SQL statements in this transaction, this process, if any SQL statement fails, the transaction will be rolled back, other SQL data changes are restored

All SQL in a transaction will either succeed or fail together. The transaction function ensures consistency of our data and adds the transaction to the business logic component