zoukankan      html  css  js  c++  java
  • SpringTest 使用说明 -构建无污染纯绿色事务测试框架 (记录用)

    @ContextConfiguration({"classpath:applicationContext.xml","classpath:spring/buyer/applicationContext-service.xml"})
    导入配置文件,这里我的applicationContext配置文件是根据模块来分类的。如果有多个模块就引入多个“applicationContext-service.xml”文件。
    如果所有的都是写在“applicationContext。xml”中则这样导入: @ContextConfiguration(locations = "classpath:applicationContext.xml")
    @RunWith(SpringJUnit4ClassRunner.class) SpringJUnit支持,由此引入Spring-Test框架支持!
    @Transactional 这个非常关键,如果不加入这个注解配置,事务控制就会完全失效!

    @TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = true)这里的事务关联到配置文件中的事务控制器(transactionManager = "transactionManager"),同时指定自动回滚(defaultRollback = true)。这样做操作的数据才不会污染数据库!

    @RunWith(SpringJUnit4ClassRunner.class)
    @Transactional
    @TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = true)
    @ContextConfiguration(locations = "classpath:applicationContext.xml")
    public class NodeServiceTest extends AbstractJUnit4SpringContextTests {
    //balabala
    }
    
  • 相关阅读:
    寒假学习进度8
    寒假学习进度7
    寒假学习进度6
    寒假学习进度5
    寒假学习进度4
    寒假学习进度3
    寒假自学进度13
    Python引用某一文件的方法出现红色波浪线
    寒假自学进度11
    正则表达式(学习)
  • 原文地址:https://www.cnblogs.com/lyq-blogs/p/spring-test.html
Copyright © 2011-2022 走看看