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
    }
    
  • 相关阅读:
    常用的android弹出对话框
    Android 启动后台运行程序(Service)
    java 日期获取时间戳
    stringbuffer与stringbuilder的区别
    Linux记录-sysctl.conf优化方案
    Linux记录-salt分析
    Hadoop记录-fair公平调度队列管理
    Linux记录-GC分析
    Hadoop记录-hdfs转载
    Linux记录-salt-minion安装
  • 原文地址:https://www.cnblogs.com/lyq-blogs/p/spring-test.html
Copyright © 2011-2022 走看看