java eight-part spring + mybatis

Spring Common Annotations (Absolutely Classic)_spring Annotations-CSDN Blog

Framework-02-Spring-Is singleton bean thread-safe_bilibili_bilibili

1.spring.bean singleton + thread unsafe

2.AOP

In the project, we can record user login logs and use request to obtain name, IP, request method, URL, and time.

Spring transaction Transactional and dynamic proxy (3) - Transaction failure scenario - Sheep riding a dragon - Blog Park (cnblogs.com)

3. Transaction failure

In-depth understanding of Spring transactions: getting started, usage, principles - Tencent Cloud Developer Community - Tencent Cloud (tencent.com)

Framework-04-Spring-Transaction Failure Scenario_bilibili_bilibili

12 scenarios of spring transaction failure_spring intercepts duplicatekeyexception without throwing exceptions - CSDN Blog

3.1 The unchecked exception is caught by try and spring cannot receive the message.

If there is an abnormal operation between two sets of database operations in a spring transaction, it is not caught by try. Then the java code reports an error and the transaction will be automatically rolled back, no problem.

If the exception try catch is handled, it is easy to cause the transaction to fail. The database operation was done in the previous section, but not in the section after the exception, and it jumped directly to the catch.

3.2 Spring will not roll back if a checked exception is thrown

3.3 Transaction methods are not public

3.4 Other scenarios

12 scenarios of spring transaction failure_spring intercepts duplicatekeyexception without throwing exceptions - CSDN Blog

Spring transaction Transactional and dynamic proxy (3) - Transaction failure scenario - Sheep riding a dragon - Blog Park (cnblogs.com)

In my project, the in-class method calls the transaction method, which causes the transaction to fail. Because this is not managed by spring, the transaction can be executed by getting the context proxy object to call it.

4.Bean life cycle (not very impressive)

5. Circular reference of beans (classes are attributes of each other) --> Level 3 cache

You need to understand the bean life cycle. The bean here only constructs a semi-finished product, but there is no subsequent initialization process.

 

The first-level cache cannot solve it, but the cooperation of first- and second-level cache can solve it.

Inject the secondary cache semi-finished product A as an object into the semi-finished product B. You can complete a singleton B first, and then A can also be completed.

5.1 Second-level cache solves general circular references

 

5.2 Level 3 cache can solve the circular dependency of proxy objects

5.3 Constructor circular reference

 5.4 Popular understanding of cache creation

It is to complete the creation process of an object by injecting a reference to an object that has not been fully initialized. Then when another object is created, the object pointed to by the previously assigned reference changes from an incompletely initialized object to a fully initialized object.

I think that after the construction is completed, the reference relationship between A and B forms a ring. Singleton A points to singleton B, singleton B points to singleton A, and there is only one A and B; not the same as the normal creation. Layer upon layer, creating multiple nests of A and B, causing memory overflow.

5.5 Why does the third-level cache need the second-level cache?

Because during the process, A's factory will create a semi-finished product agent A and put it in the second-level cache, including when B later gets the agent A package, it will get it from here and when it injects B into the semi-finished product A to make A complete, this can guarantee You always use an object (single case). If you don't use the second level cache, you need to call A's factory multiple times to create the object, which is a multiple instance.

5.6 Why the proxy object cannot be created at the second level------This article made me suddenly enlightened

 From reflection to dynamic proxy to aop to spring why three-level cache is needed_aop and three-level cache-CSDN Blog

That is, after the secondary structure is constructed, proxy A is inside proxy B, but inside proxy B is the original A, not proxy A. Therefore, it cannot be considered a complete proxy object without forming a cycle. 

6.SpringMVC important components (4)

old jsp

current development

7.SpringBoot automatic configuration principle

8.Common annotations for Spring, mvc, and boot

9.MyBatis execution process

xml configuration file-->Build a unique sql session factory-->Construct a session-->Call the executor to operate the database interface-->The executor will combine the java object with the dao interface according to the mapping of the configured mapper tag and dao interface as needed. Convert sql objects to perform database operations and return java object results

10.mybatis lazy loading (a bit like a lazy man)

11. Mybatis’s first-level and second-level cache

12. Druid connection pool (mybatis connection pool of your own project)

Database connection pool (commonly used Druid)_Is the connection pool stream not closed - CSDN Blog

It has good performance, scalability, and logging function.

Guess you like

Origin blog.csdn.net/m0_50973548/article/details/135187331