天天看點

Mapper測試;類報錯,和分頁相關

如果Mybatis-congfig配置檔案中有分頁配置:

<!-- 分頁插件 -->
<!--  <plugins>
      <plugin interceptor="com.github.pagehelper.PageInterceptor">
          <property name="reasonable" value="true"/>
      </plugin>
  </plugins>-->      

那麼在pom中必須有相應依賴:

<!--  <dependency>
    <groupId>com.github.pagehelper</groupId>
    <artifactId>pagehelper</artifactId>
    <version>5.0.0</version>
  </dependency>-->      

否則,會使Mapper測試類:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath:applicationContext.xml"})
public class MapperTest {
    @Autowired
    DepartmentMapper departmentMapper;
    @Test
    public void testCRUD(){

        System.out.println(departmentMapper);
        departmentMapper.insertSelective(new Department(null,"開發部門"));
        departmentMapper.insertSelective(new Department(null,"測試部門"));
    }
}      

報如下錯誤:

嚴重: Caught exception while allowing TestExecutionListener [org.springframewor[email protected]38082d64]to prepare test instance [[email protected]]

java.lang.IllegalStateException: Failed toload ApplicationContext

         atorg.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124)

         atorg.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:83)

這是因為測試檔案加載applicationContext配置問件,進而加載Mybatis-congfig配置檔案,會發現缺少依賴的錯誤。