Spring - 无法解析 beans.xml 中的测试 class

Spring - cannot resolve test class in beans.xml

我对 Spring 框架还很陌生,所以这个问题可能看起来有点傻

我正在尝试在 test.java 包中创建摘要 class Test.class 并使用 Spring configuration.xml 文件对其进行配置。此文件在 test.resources 包中,看起来像:

<beans>

    ... schema URLs ...

    <bean abstract="true" id="test" class="Test" />

</beans>

检查说:

Cannot resolve class 'Test'

Idea 礼貌地让我创建 Test.class。我同意,它已在 main.java 包中创建。但是有点乱。我不希望它在那里。

Test.class代码:

@RunWith(SpringJUnitClassRunner.class)
@ContextConfiguration(locations = {"/configuration.xml"})
public abstract class Test {

abstract void test();

}

我错过了什么?

下一行应更改为指向完全限定的 class 名称:-

  <bean abstract="true" id="test" class="test.java.Test" />

The class attribute defines the type of the bean and uses the fully qualified classname.

引自link.

原来 resource 文件夹很重要。最初 configuration.xml 是在 main 包的 resources 文件夹中创建的,然后移动到 test 包的 resources 文件夹。这就是这种行为的原因。 configuration.xml 删除后,resources 文件夹重新标记和在 test 包的 resources 文件夹中创建新 configuration.xml 问题已解决。