Configure mybatis secondary cache
1 brief description
2 Configuration
1 Update the configuration file and turn on the second-level cache.
2 Entity classes automatically realize serial numbers.
2* Knowledge point-why entity classes need to be serialized.
The two most important reasons are:
1. Save the state of the object in the storage medium for You can recreate the exact same copy later;
2. Send the object from one application domain to another by value.
The purpose of implementing the serializable interface is to store the object in the byte stream and then restore it. So you think if your object is not serialized, how can it be transmitted over the network? If network transmission is required, it must be converted to a byte stream. So in distributed applications, you have to implement serialization. , Then there is no need to achieve serialization.
3 Add bean tool class ApplicationContextHolder
3* Solve the dependency problem In the
previous step, Validate in the tool class depends on lang3, and the dependency is added to the common service
3 *Solve the path scanning problem. The
startup class updates the scan path. By default, only the files in the package where the startup class is located are scanned
4 Add a tool class that implements the MyBatis Cache interface
4.*In order to solve the dependency problem, introduce the
mapper in the jar 5 service to realize the cache tool class
. The first query is to go to the database, and then to go to the cache;
3 Test verification After the
configuration is completed, the operations of
adding , deleting, modifying and checking will automatically refresh the second-level cache. The specific test is omitted. 1 Solve the redis connection pool problem-increase dependency