Will be declared as a class annotation of Spring bean of what?

We generally use automatic assembling @Autowired annotation bean, in order to identify the class to be used for the bean-based automatic assembly @Autowired annotation, the annotation may be implemented using the following:

  • @Component: General notes, any class may be marked Spring assembly. If you belong to a Bean does not know take a layer, you can use
  • @Component comment mark.
  • @Repository: i.e. the corresponding persistence Dao layer, mainly for database-related operations.
  • @Service: the corresponding service layer mainly related complex logic, need to use Dao layer.
  • @Controller: Spring MVC corresponding to the control layer, the primary user accepts the user request and returns the data to the call Service layer front page.

Spring fashion management services are there?

编程式事务,在代码中硬编码。(不推荐使用)
声明式事务,在配置文件中配置(推荐使用)

Declarative transaction is divided into two types:

基于XML的声明式事务
基于注解的声明式事务

Spring transaction isolation level, which has several?

TransactionDefinition 接口中定义了五个表示隔离级别的常量:
TransactionDefinition.ISOLATION_DEFAULT: 使用后端数据库默认的隔离级别,Mysql 默认采用的 REPEATABLE_READ隔离级别 Oracle 默认采用的 READ_COMMITTED隔离级别.
TransactionDefinition.ISOLATION_READ_UNCOMMITTED: 最低的隔离级别,允许读取尚未提交的数据变更,可能会导致脏读、幻读或不可重复读TransactionDefinition.ISOLATION_READ_COMMITTED: 允许读取并发事务已经提交的数据,可以阻止脏读,但是幻读或不可重复读仍有可能发生TransactionDefinition.ISOLATION_REPEATABLE_READ: 对同一字段的多次读取结果都是一致的,除非数据是被本身事务自己所修改,可以阻止脏读和不可重复读,但幻读仍有可能发生。
TransactionDefinition.ISOLATION_SERIALIZABLE: 最高的隔离级别,完全服从ACID的隔离级别。所有的事务依次逐个执行,这样事务之间就完全不可能产生干扰,也就是说,该级别可以防止脏读、不可重复读以及幻读。但是这将严重影响程序的性能。通常情况下也不会用到该级别。

? Spring What kinds of transaction propagation behavior Affairs
supports the current transaction situation:

TransactionDefinition.PROPAGATION_REQUIRED: 如果当前存在事务,则加入该事务;如果当前没有事务,则创建一个新的事务。
TransactionDefinition.PROPAGATION_SUPPORTS: 如果当前存在事务,则加入该事务;如果当前没有事务,则以非事务的方式继续运行。
TransactionDefinition.PROPAGATION_MANDATORY: 如果当前存在事务,则加入该事务;如果当前没有事务,则抛出异常。(mandatory:强制性)不支持当前事务的情况:
TransactionDefinition.PROPAGATION_REQUIRES_NEW: 创建一个新的事务,如果当前存在事务,则把当前事务挂起。
TransactionDefinition.PROPAGATION_NOT_SUPPORTED: 以非事务方式运行,如果当前存在事务,则把当前事务挂起。
TransactionDefinition.PROPAGATION_NEVER: 以非事务方式运行,如果当前存在事务,则抛出异常。

Other cases:
TransactionDefinition.PROPAGATION_NESTED: If the current transaction exists, create a nested transaction transaction as the current transaction to run; if no transaction, the value is equivalent to TransactionDefinition.PROPAGATION_REQUIRED.

Published 42 original articles · won praise 0 · Views 931

Guess you like

Origin blog.csdn.net/mojiezhao/article/details/104160674