java - 无法识别 @ContextConfiguration 的参数类

标签 java spring context-configuration

在下面的测试类中

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import static org.junit.Assert.assertNotNull;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes=CDPlayerConfig.class)
public class CDPlayerTest {

    @Autowired
    private CompactDisc cd;

    @Test
    public void cdShouldNotBeNull(){
        assertNotNull(cd);
    }
}

编译器突出显示行中的参数类

@ContextConfiguration(classes=CDPlayerConfig.class)

作为一个错误。 CDPlayerConfing类很容易找到,它被标记为Config类

@Configuration
@ComponentScan
public class CDPlayerConfig {
}

我错过了一些导入吗?

最佳答案

我找到了解决方案。我一直在使用旧的 Maven 依赖项进行测试

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-test</artifactId>
        <version>3.0.5.RELEASE</version>
        <scope>test</scope>
    </dependency>

我已经更改了 5.0.1.RELEASE 的版本并且它有效。

关于java - 无法识别 @ContextConfiguration 的参数类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53800745/

相关文章:

java - 为色盲人士增强图像

java - Thymeleaf:检查是否定义了变量

java - Java 中带有 CRAM-MD5 的 SMTP

java - 确定 List<> 的通用参数

Spring+Hibernate+Ehcache让query_cache永不过期

java - Spring 上下文层次结构中的 bean 销毁顺序

android - 如何防止 Android 设备在我的应用程序中显示尺寸缩放?

java 实例方法和变量的继承解析

java - 无法填充池 : when starting jboss application