springboot整合mybatise出现mybatis-spring-boot-starter-test不兼容的问题

Marvin-Fox 2019-07-25 07:57:40
我在学习springboot的过程中,融合mybatise项目可以跑起来,
但是在写针对mybatise的junit测试时,出现了异常。
网上说可能是依赖版本的兼容性问题,我试了几个版本还是没有解决
现在我不知道这个到底是什么问题,或者应该用什么版本可以进行匹配

我用的是jdk 1.8
下面是我的报错信息:
java.lang.IllegalStateException: Could not load TestContextBootstrapper [null]. Specify @BootstrapWith's 'value' attribute or make the default bootstrapper class available.
at org.springframework.test.context.BootstrapUtils.resolveTestContextBootstrapper(BootstrapUtils.java:143)
at org.springframework.test.context.TestContextManager.<init>(TestContextManager.java:105)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTestContextManager(SpringJUnit4ClassRunner.java:152)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.<init>(SpringJUnit4ClassRunner.java:143)
at org.springframework.test.context.junit4.SpringRunner.<init>(SpringRunner.java:49)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104)
at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:33)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:41)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:211)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:67)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Caused by: org.springframework.core.annotation.AnnotationConfigurationException: Attribute 'excludeAutoConfiguration' in annotation [org.mybatis.spring.boot.test.autoconfigure.MybatisTest] is declared as an @AliasFor nonexistent attribute 'exclude' in annotation [org.springframework.boot.autoconfigure.ImportAutoConfiguration].; nested exception is java.lang.NoSuchMethodException: org.springframework.boot.autoconfigure.ImportAutoConfiguration.exclude()
at org.springframework.core.annotation.AnnotationUtils$AliasDescriptor.<init>(AnnotationUtils.java:2066)
at org.springframework.core.annotation.AnnotationUtils$AliasDescriptor.from(AnnotationUtils.java:2033)
at org.springframework.core.annotation.AnnotationUtils.getAttributeAliasNames(AnnotationUtils.java:1703)
at org.springframework.core.annotation.AnnotationUtils.getAttributeAliasMap(AnnotationUtils.java:1616)
at org.springframework.core.annotation.AbstractAliasAwareAnnotationAttributeExtractor.<init>(AbstractAliasAwareAnnotationAttributeExtractor.java:65)
at org.springframework.core.annotation.DefaultAnnotationAttributeExtractor.<init>(DefaultAnnotationAttributeExtractor.java:45)
at org.springframework.core.annotation.AnnotationUtils.synthesizeAnnotation(AnnotationUtils.java:1449)
at org.springframework.core.annotation.AnnotationUtils.synthesizeAnnotation(AnnotationUtils.java:1432)
at org.springframework.core.annotation.AnnotatedElementUtils$MergedAnnotationAttributesProcessor.postProcess(AnnotatedElementUtils.java:1578)
at org.springframework.core.annotation.AnnotatedElementUtils$MergedAnnotationAttributesProcessor.postProcess(AnnotatedElementUtils.java:1528)
at org.springframework.core.annotation.AnnotatedElementUtils.searchWithFindSemantics(AnnotatedElementUtils.java:1162)
at org.springframework.core.annotation.AnnotatedElementUtils.searchWithFindSemantics(AnnotatedElementUtils.java:1086)
at org.springframework.core.annotation.AnnotatedElementUtils.searchWithFindSemantics(AnnotatedElementUtils.java:1060)
at org.springframework.core.annotation.AnnotatedElementUtils.findAllMergedAnnotations(AnnotatedElementUtils.java:789)
at org.springframework.test.context.BootstrapUtils.resolveExplicitTestContextBootstrapper(BootstrapUtils.java:150)
at org.springframework.test.context.BootstrapUtils.resolveTestContextBootstrapper(BootstrapUtils.java:126)
... 22 more
Caused by: java.lang.NoSuchMethodException: org.springframework.boot.autoconfigure.ImportAutoConfiguration.exclude()
at java.lang.Class.getDeclaredMethod(Class.java:2122)
at org.springframework.core.annotation.AnnotationUtils$AliasDescriptor.<init>(AnnotationUtils.java:2059)
... 37 more


我用的是intellij
===============maven依赖的配置在这里===============

<!-- Spring boot 父引用-->
<!--继承Spring Boot默认配置-->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.4.RELEASE</version>
</parent>

<dependencies>
<!--添加第一个Boot Web启动器-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<!--添加database-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.34</version>
</dependency>
<!--添加myBatis-->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.1.0</version>

</dependency>
<!--用于myBatis的junit测试 -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter-test</artifactId>
<version>2.1.0</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

<!--jsp依赖支持-->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<!--<scope>provided</scope>-->
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>


<dependency>
<groupId>ai.ost</groupId>
<artifactId>fastjson-protobuf</artifactId>
<version>0.1.1</version>
<type>pom</type>
</dependency>


<!--base-->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
</dependencies>


===============这里是junit 测试类===============


import com.marvin.demo.dao.UsersBeanMapper;
import com.marvin.demo.entity.UsersBean;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mybatis.spring.boot.test.autoconfigure.MybatisTest;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.junit4.SpringRunner;

import javax.annotation.Resource;
import java.util.List;

/**
* Created by Marvin on 2019/7/22.
*/
@RunWith(SpringRunner.class)
//@SpringBootTest
//使用@MybatisTest 替换@SpringBootTest
@MybatisTest
//使用@MybatisTest 默认会使用虚拟的数据源替代你配置的,如果想使用你配置的数据源操作真正的数据库则使用下面这个(Replace.NONE表示不替换数据源配置)
//@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
public class TestMybatis {

@Resource
private UsersBeanMapper usersBeanMapper;

@Test
@Rollback(false)
public void testName() throws Exception {
List<UsersBean> list=usersBeanMapper.selectAll();
System.out.print(list.size());

}
}


下面是我项目里的依赖包







我是springboot新手,求大神们帮忙看一下这个问题,非常感谢
...全文
804 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
YouZhaBaoZi 2019-08-28
  • 打赏
  • 举报
回复
吧 除了springboot 其他的组件的版本都删了吧
Heartack 2019-08-28
  • 打赏
  • 举报
回复
测试的话之需要spring-boot-starter-test 就可以了,不需要其他的测试包
Marvin-Fox 2019-08-24
  • 打赏
  • 举报
回复
求助啊,有没有大神可以解答一下

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧