Spring family bucket learning (3)

Preface:

September last year, my colleagues and I at the time geeks bought Ding Xuefeng Spring family bucket of learning, the curriculum is divided into 16 chapters in total, I have learned the most part, are recorded in a notebook before, today I want to record on the Blog, Share more knowledge to those in need of help, I will be the number of chapters as the content of the article, the original course speak in more detail, I am here to do a summary on some specific points.

.Spring of a transaction abstraction

Consistent transaction model 

  • JDBC/Hibernate/myBatis
  • Dtsourche / Jria

 Transaction abstraction of core interfaces

PlatformTransactionManager

  • DataSourceTransactionManager
  • HibernateTransactionManager
  • JtaTransactionManager

TransactionDefinition

  • Propagation
  • Islation
  • Timeout
  • Read-only status

 Transaction propagation characteristics

Transmissible value description
PROPAGATION_REQUIDED 0 We have to use the current transaction, not just with the new
PROPAGATION_SUPPORTS 1 Transaction optional, not required
PROPAGATION_MANDATORY 2 Current affairs must be, otherwise Throws
PROPAGATION_REQUIRES_NEW 3 Whether or not there is a transaction, all from a new transaction
PROPAGATION_NOT_SUPPORTED 4 It does not support transactions, run by a non-transactional way
PROPAGATION_NEVER 5 It does not support transactions, if the transaction is Throws
PROPAGATION_NESTED 6 There are currently Affairs renewed a transaction in the current transaction

Transaction isolation characteristics

 

Isolation value Dirty read Non-repeatable read Magic Reading
ISOLATION_READ_UNCOMMITTED 1 yes yes yes
ISOLATION_READ_COMMITTED 2 no yes yes
ISOLATION_REPEATABLE_READ 3 no no yes
ISOLATION_SERIALIZABLE 4 no no no

Programmatic transaction 

TransactionTemplate

  • TransactionCallback
  • TransactionCallbackWithoutResult

PlatformTransactionManager

  • Can be defined incoming TransactionDefinition

 


Declarative transaction

https://www.cnblogs.com/ooo0/p/11029629.html 


Annotation-based configuration

 Notes affairs open way:

  • @EnableTransactionManagement
  • <tx:annotation-driven/>

Some configuration

  • proxy target class
  • model
  • order

 

@Transactional

  • transactionManager
  • propagation
  • isolation
  • timeout
  • readOnly
  • How to determine the rollback

 

 

Two. Spring's JDBC abstraction abnormal

Spring abnormal conversion into a data manipulation will DataAccessException

Either use data access, will use the same exception

Spring is understanding how those error codes?

  • By SQLErrotCodeSQLExceptionTranslator parse error code

ErrorCode defined

  • org/springframework/jdbc/support/sql-error-codes.xml
  • sql-error-codes.xml under Classpath

 

SpringBoot custom error code

Three. SpringBoot common comment

Refer to: https://blog.csdn.net/tangthh123/article/details/104092510

 Four. Actuator

Some nice Endpoint Actuator provided
URL effect
/actuator/health health examination
/actuator/beans View all Bean container
/actuator/mapping View Web URL mapping
/actuator/env View Environmental Information

Ban all Endpoint

 application.properties configuration parameters or application.yml

management.endpoints.web.exposure.include=*

V. multiple data sources. Sub-library sub-table. Relations separate read and write

1. Several common

  • The system needs to access several different databases, this time can be configured both data sources
  • The system requires access to the primary library and the library with a library of backup, that is, to use a separate read and write time, a main library, both a standby database, the data source configured individually, write separation
  • The system requires access to a database as a set of sub-library sub-table (vertical split, horizontal split), try to use database middleware.

 

Nature VI. Affairs

The declarative nature of the transaction by Spring AOP is to enhance the functionality of the class.

The nature Spring AOP is a proxy for the class to do

  • Call appears in its own way, eh, it is the actual use of the enhanced proxy class

Problem Solution:

  • The method of the proxy class after the visit enhanced, rather than direct access to its own method

 

VII. Slow logging configuration

Alibaba launched a number of database connection pool Description:

System Configuration Properties

  • druid.stat.logSlowSql=true
  • druid.stat.slowSqlMillis=3000

SpringBoot

  • spring.datasource.druid.filter.stat.enabled=true
  • spring.datasource.druid,filter.stat.log-slow-sql=true
  • spring.datasource.druid.filter.stat.slow-sql-millis=3000

 

 

 

Published 66 original articles · won praise 49 · views 20000 +

Guess you like

Origin blog.csdn.net/tangthh123/article/details/105064233