您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

springboot单元测试依赖踩坑实例源码分析

2024/6/1 1:56:08发布59次查看
springboot单元测试依赖踩坑在进行springboot 单元测试的时候,发现如下错误。
java.lang.illegalstateexception: could not load cacheawarecontextloaderdelegate [class org.springframework.test.context.cache.defaultcacheawarecontextloaderdelegate]
    at org.springframework.test.context.bootstraputils.createcacheawarecontextloaderdelegate(bootstraputils.java:103)
    at org.springframework.test.context.bootstraputils.createbootstrapcontext(bootstraputils.java:72)
    at org.springframework.test.context.testcontextmanager.<init>(testcontextmanager.java:124)
    at org.springframework.test.context.junit4.springjunit4classrunner.createtestcontextmanager(springjunit4classrunner.java:151)
    at org.springframework.test.context.junit4.springjunit4classrunner.<init>(springjunit4classrunner.java:142)
    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:423)
    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 org.junit.internal.requests.filterrequest.getrunner(filterrequest.java:36)
    at com.intellij.junit4.junit4ideatestrunner.startrunnerwithargs(junit4ideatestrunner.java:49)
    at com.intellij.rt.execution.junit.ideatestrunner$repeater.startrunnerwithargs(ideatestrunner.java:47)
    at com.intellij.rt.execution.junit.junitstarter.preparestreamsandstart(junitstarter.java:242)
    at com.intellij.rt.execution.junit.junitstarter.main(junitstarter.java:70)
caused by: org.springframework.beans.beaninstantiationexception: failed to instantiate [org.springframework.test.context.cache.defaultcacheawarecontextloaderdelegate]: unresolvable class definition; nested exception is java.lang.nosuchmethoderror: org.springframework.core.kotlindetector.iskotlinreflectpresent()z
    at org.springframework.beans.beanutils.instantiateclass(beanutils.java:132)
    at org.springframework.beans.beanutils.instantiateclass(beanutils.java:152)
    at org.springframework.test.context.bootstraputils.createcacheawarecontextloaderdelegate(bootstraputils.java:100)
    ... 20 more
caused by: java.lang.nosuchmethoderror: org.springframework.core.kotlindetector.iskotlinreflectpresent()z
    at org.springframework.beans.beanutils.instantiateclass(beanutils.java:171)
    at org.springframework.beans.beanutils.instantiateclass(beanutils.java:122)
    ... 22 more
一天以前单测是能跑的,初步预计是依赖的问题。由于项目采用了多模块结构,模块间的引用较多,因此需要逐一检查每个模块是否存在问题。
如下步骤1. 在出现问题的单测归属模块的pom文件中,找到所有模块间依赖
2. 依次到各个模块进行单元测试,定位问题模块
3. 排查问题模块的依赖问题
一番折腾,发现问题模块 carrier-api
再往下深入,检查carrier-api依赖
幸运的是,问题的根源迅速被发现,是由于spring-web的引用导致的错误。将该引用注释掉,并且将相关代码进行引用替换。
问题解决
以上就是springboot单元测试依赖踩坑实例源码分析的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product