获取java.lang.IllegalStateException:在使用Spring运行Cucumber测试时无法加载CacheAwareContextLoaderDelegate异常

获取java.lang.IllegalStateException:在使用Spring运行Cucumber测试时无法加载CacheAwareContextLoaderDelegate异常,spring,gradle,java-8,cucumber,junit4,Spring,Gradle,Java 8,Cucumber,Junit4,我正在尝试将cucumebr测试与弹簧集成。我已经在带有Spring注释的包操作下创建了名为MyClass的类@Component package actions; import org.springframework.stereotype.Component; @Component public class MyClass{ public void printSomething(){ System.out.println("Print this); } 使用Spring注释创建了A

我正在尝试将cucumebr测试与弹簧集成。我已经在带有Spring注释的包
操作
下创建了名为
MyClass
的类
@Component

package actions;
import org.springframework.stereotype.Component;

@Component
public class MyClass{
public void printSomething(){
    System.out.println("Print this);
}
使用Spring注释创建了
AppConfig
@ComponentScan
。并将上面创建的包
(actions)
传递到
@ComponentScan

import org.springframework.context.annotation.ComponentScan;

@ComponentScan(basePackages = {"actions"})
public class AppConfig {

}
在gluecode中,我使用
@Autowired

@ContextConfiguration(classes=AppConfig.class)
public StepDefinitions implements En{

    @Autowired private MyClass myClass;

    public StepDefinitions(){   
        Before(() -> {
            myClass.printSomething();           
        });
下面是我的Cumber test runenr课程

import org.springframework.test.context.ContextConfiguration;

@RunWith(Cucumber.class)
@CucumberOptions(
              features = "myfeature.feature"
              ,glue={"stepDefinitions"}
              )
@ContextConfiguration(classes=AppConfig.class)
public class TestRunner{

}
当我作为junit测试运行TestRunner时,junit抛出以下错误

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 cucumber.runtime.java.spring.CucumberTestContextManager.<init>(SpringFactory.java:206)
    at cucumber.runtime.java.spring.SpringFactory.start(SpringFactory.java:102)
    at cucumber.runtime.java.JavaBackend.buildWorld(JavaBackend.java:123)
    at cucumber.runtime.Runtime.buildBackendWorlds(Runtime.java:141)
    at cucumber.runtime.model.CucumberScenario.run(CucumberScenario.java:38)
    at cucumber.runtime.junit.ExecutionUnitRunner.run(ExecutionUnitRunner.java:102)
    at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:63)
    at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:18)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at cucumber.runtime.junit.FeatureRunner.run(FeatureRunner.java:70)
    at cucumber.api.junit.Cucumber.runChild(Cucumber.java:95)
    at cucumber.api.junit.Cucumber.runChild(Cucumber.java:38)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at cucumber.api.junit.Cucumber.run(Cucumber.java:100)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:539)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:761)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:461)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:207)
Caused by: java.lang.NoSuchMethodError: org.springframework.beans.BeanUtils.instantiateClass(Ljava/lang/Class;Ljava/lang/Class;)Ljava/lang/Object;
    at org.springframework.test.context.BootstrapUtils.createCacheAwareContextLoaderDelegate(BootstrapUtils.java:100)
    ... 32 more
我使用gradle作为构建工具。下面是我添加的依赖项列表

compile group: 'org.springframework', name: 'spring', version: '2.5.6'
    compile group: 'org.springframework', name: 'spring-aop', version: '5.0.7.RELEASE'
    compile group: 'org.springframework', name: 'spring-aspects', version: '5.0.7.RELEASE'
    compile group: 'org.springframework', name: 'spring-beans', version: '5.0.7.RELEASE'
    compile group: 'org.springframework', name: 'spring-context', version: '5.0.7.RELEASE'
    compile group: 'org.springframework', name: 'spring-context-support', version: '5.0.7.RELEASE'
    compile group: 'org.springframework', name: 'spring-core', version: '5.0.7.RELEASE'
    compile group: 'org.springframework', name: 'spring-expression', version: '5.0.7.RELEASE'
    compile group: 'org.springframework', name: 'spring-instrument', version: '5.0.7.RELEASE'
    compile group: 'org.springframework', name: 'spring-instrument-tomcat', version: '4.3.18.RELEASE'
    compile group: 'org.springframework', name: 'spring-jdbc', version: '5.0.7.RELEASE'
    compile group: 'org.springframework', name: 'spring-jms', version: '5.0.7.RELEASE'
    compile group: 'org.springframework', name: 'spring-messaging', version: '5.0.7.RELEASE'
    compile group: 'org.springframework', name: 'spring-orm', version: '5.0.7.RELEASE'
    compile group: 'org.springframework', name: 'spring-oxm', version: '5.0.7.RELEASE'
    compile group: 'org.springframework', name: 'spring-test', version:'5.0.7.RELEASE'
    compile group: 'org.springframework', name: 'spring-tx', version:'5.0.7.RELEASE'
    compile group: 'org.springframework', name: 'spring-web', version:'5.0.7.RELEASE'
    compile group: 'org.springframework', name: 'spring-webmvc', version:'5.0.7.RELEASE'
    compile group: 'org.springframework', name: 'spring-webmvc-portlet', version: '4.3.18.RELEASE'

谁能告诉我导致异常的问题吗。是否有任何依赖项我需要包括,或者是否有任何特定的runner我应该用来调用springs中的
cucumber junit
,而不是
cucumber。类

从gradle构建中删除不需要的依赖项为我解决了这个问题。代码中没有错误

只是在下面添加了依赖项并删除了所有依赖项

compile group: 'org.springframework', name: 'spring-context', version: '5.0.7.RELEASE'
compile group: 'org.springframework', name: 'spring-core', version: '5.0.7.RELEASE'
compile group: 'org.springframework', name: 'spring-test', version:'5.0.7.RELEASE'
compile group: 'org.springframework', name: 'spring-tx', version:'5.0.7.RELEASE'

我试着只在StepDefinitions.java类和TestRunenr.java类中给出@ContextConfiguration(classes=AppConfig.class),也试着在这两个类中给出。每次都会得到相同的异常。
compile group: 'org.springframework', name: 'spring-context', version: '5.0.7.RELEASE'
compile group: 'org.springframework', name: 'spring-core', version: '5.0.7.RELEASE'
compile group: 'org.springframework', name: 'spring-test', version:'5.0.7.RELEASE'
compile group: 'org.springframework', name: 'spring-tx', version:'5.0.7.RELEASE'