Spring Boot註解補遺小結

引言

常用註解

  • @ContextConfiguration(classes=AppConfig.class) 引入applicationContext, AppConfig.class爲@Configuration修飾的類
    用來在單元測試中引入@ApplicationContext,以及在AppConfig.java中掃描引入的類實例。
  • @Profile(“name”)
  • @ActivieProfiles(“name”)
  • @EnableTransactionManagement
  • @EnableJpaRepositories(“com.xx.package.xx”)
  • @Transactional. : 在單元測試中使用,允許其在執行完畢後回滾

Propagation Levels

REQUIRED(default):
tx --> join tx
not --> create and run tx

REQUIRED NEW:
tx1 ->. suspend tx1; create and run tx2; resume tx1
no: -> create and run tx

SUPPORTS:
tx. -> join tx
no -> nothing

NOT SUPPORTED:
tx -> suspend tx, run outside tx,; resume tx;
no -> nothing
MANDATORY:
tx. -> join tx
no -> throw an exception.
NEVER:
tx -> throw an exception
no -> nothing

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章