2023-01-19
Spring宣告式事務管理屬性
一、隔離級別
1、概念:一個事務與其他事務之間的隔離等級(1,2,4,8),
2、隔離級別:
(1)讀未提交(1):READ UNCOMMTTED
存在問題:臟讀(讀取到了未提交資料)
(2)讀已提交(2):READ COMMTTED
存在問題:可能出現不可重復讀
(3)可重復讀(4):REPEATABLE READ
存在問題:可能出現幻讀
(4)串行化(8):SERIALIZABLE
二、事務超時
1、設定事務超時時間,到達指定時間后會強制事務回滾
2、型別:int,單位:秒
3、默認值:-1(未設定強制回滾)
三、事務只讀(readonly)
1、一般事務方法中只有查詢操作時,才將事務設定為只讀
2、默認值:false
四、事務回滾
1、rollbackFor:設定回滾的例外Class
2、noRollbackFor:設定不回滾例外Class
五、基于XML方式,配置宣告式事務管理
六、Spring5新特性、新注解&整合log4j2
1、添加新注解
@Nullable作用
①位置:可以書寫在方法&屬性上面&引數前面,
②作用:表示當前方法或屬性可以為空,當前屬性為空時,消除空指標例外,
2、Spring5整合Log4j2
(1)匯入jar包
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-slf4j-impl --> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-slf4j-impl</artifactId> <version>2.11.2</version> <scope>test</scope> </dependency>
(2)撰寫組態檔
<?xml version="1.0" encoding="UTF-8"?> <!--日志級別以及優先級排序:OFF>FATAL>ERROR>WARN>INFO>DEBUG>TRACE>ALL--> <!-- configuration后面的status用于設定log4j2自身內部的資訊輸出,可以不設定,當設定成trace時,可以看到log4j2內部各種詳細輸出--> <configuration status="INFO"> <!-- 先定義所有的appender--> <appenders> <!-- 輸出日志資訊到控制臺--> <console name="Console" target="SYSTEM_OUT"> <!-- 控制日志輸出的格式--> <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} -%msg%n"></PatternLayout> </console> </appenders> <!-- 然后定義logger,只有定義了logger并引入的appender,appender才會生效--> <!-- root:用于指定專案的根日志,如果沒有單獨指定Logger,則會使用root作為默認的日志輸出--> <loggers> <root level="DEBUG"> <appender-ref ref="Console"></appender-ref> </root> </loggers> </configuration>
七、Spring5整合Junit5
1、匯入jar包(注:將Junit4的jar包洗掉)
<!-- https://mvnrepository.com/artifact/org.springframework/spring-context --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version>5.3.10</version> </dependency> <!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api --> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-api</artifactId> <version>5.7.2</version> <scope>test</scope> </dependency>
2、使用注解整合即可
(1)整合方式一
@ContextConfiguration(locations = "classpath:applicationContext_transactionmanager.xml") @ExtendWith(SpringExtension.class)
(2)整合方式二
@SpringJUnitConfig(locations = "classpath:applicationContext_transactionmanager.xml")
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/542261.html
標籤:其他
上一篇:Python如何運行程式
下一篇:Loj 507 接竹竿 題解
