This is the 8th day of my participation in Gwen Challenge
IOC and AOP
IOC
- The Inverse of Control is a design concept, while the Inverse of Control is not unique to Spring.
- When you need to create an object, you just need to configure the configuration file/annotations and hand them over to the Spring framework.
- IoC container is the carrier used by Spring to implement IoC. IoC container is actually a Map (key, value), which stores various objects.
- benefits:
- The interdependencies between objects are managed by the iOc container, and object injection is done by the iOc container
- Simplify manual program code to maintain dependencies between objects
- The Spring IoC initialization process
AOP
- Aspect-oriented Programming (AOP)
- It is suitable for handling business-independent logical code that is called jointly for business modules
- Benefits: reduce system code duplication, reduce code coupling, easy maintenance
- Commonly used in:
- Transaction processing
- Log management
- Access control
Second, the spring bean
Common scope
- Singleton: A unique bean instance. Beans in Spring are singleton by default.
- Prototype: Each request creates a new bean instance.
- Request: Each HTTP request produces a new bean that is valid only within the current HTTP Request.
- Session: Each HTTP request yields a new bean that is valid only for the current HTTP session.
- Global-session: the global session scope, which is only meaningful in portlet-based web applications, is no longer available in Spring5.
Singleton bean thread safety issues
Spring transactions
Transaction isolation level in Spring
- TransactionDefinition.ISOLATION_DEFAULT
- Using the default isolation level of the back-end database,
- REPEATABLE_READ isolation level used by Mysql by default
- READ_COMMITTED Isolation level used by Oracle.
- TransactionDefinition.ISOLATION_READ_UNCOMMITTED
- The lowest isolation level,
- Allowing data changes that have not yet been committed to be read may result in dirty reads, phantom reads, or unrepeatable reads
- TransactionDefinition.ISOLATION_READ_COMMITTED
- Allows reading of data already committed by concurrent transactions,
- Dirty reads can be prevented, but phantom or non-repeatable reads can still occur
- TransactionDefinition.ISOLATION_REPEATABLE_READ
- Multiple reads of the same field are consistent, unless the data is modified by the transaction itself;
- Dirty and unrepeatable reads can be prevented, but phantom reads can still occur.
- TransactionDefinition.ISOLATION_SERIALIZABLE
- Highest isolation level, fully compliant with the ACID isolation level. All transactions are executed one by one without interfering with each other.
- Dirty reads, non-repeatable reads, and phantom reads can be prevented, but this severely affects program performance and is generally not used.
Refer to the link
- JavaGuide Spring FAQ summary
- What are the benefits of Spring IoC?