无法检测到测试类的默认资源位置:类路径资源不存在。

3

我在Jenkins中运行Maven构建时遇到了一些问题。它试图运行我的集成测试,但是一直抛出这个错误:

 java.lang.IllegalStateException: Neither GenericXmlContextLoader nor AnnotationConfigContextLoader was able to detect defaults, and no ApplicationContextInitializers were declared for context configuration [ContextConfigurationAttributes@2d10dd87 declaringClass = 'com.xxxx.api.services.MessageServiceImplIntegrationTest', locations = '{}', classes = '{}', inheritLocations = true, initializers = '{}', inheritInitializers = true, name = [null], contextLoaderClass = 'org.springframework.test.context.ContextLoader']

请查看链接以获取完整的堆栈跟踪信息 链接
1个回答

7
错误与日志中的这部分内容有关:
INFO : org.springframework.test.context.support.AbstractContextLoader - Could not detect default resource locations for test class [com.xxxx.api.services.MessageServiceImplIntegrationTest]: class path resource [com/xxxx/api/services/MessageServiceImplIntegrationTest-context.xml] does not exist
INFO : org.springframework.test.context.support.AnnotationConfigContextLoaderUtils - Could not detect default configuration classes for test class [com.xxxx.api.services.MessageServiceImplIntegrationTest]: MessageServiceImplIntegrationTest does not declare any static, non-private, non-final, inner classes annotated with @Configuration.

基本上,你的测试类没有配置部分(无论是xml还是@Configuration),它可以用来构建应用程序上下文。

请参阅此链接了解使用XML进行测试配置,以及此链接关于使用@Configuration注释的配置。


这不是真的,而是我的错,我没有展示我的实际测试,请查看链接link。我在与测试相同的位置中有一个MessageServiceImplIntegrationTest-context.xml文件,因为Spring文档说它会加载它(如果在“locations”中未包含)并使用测试名称加上“-context.xml”从类路径加载它。当我从eclipse运行Maven测试时,它被找到并且测试通过。当我将其部署到jenkins时,它运行然后抱怨找不到该文件。 - Dean
你没有提到它是否与Maven测试一起工作。嗯,那么问题可能出在Jenkins设置和某些类路径配置上,而不是Spring。 - Andrei Stefan
我认为更可能是类路径的问题,但是我该如何检查呢?特别是从Jenkins或STS中是否有可能进行检查。另外,Jenkins或Maven用哪个文件来确定类路径?我认为这个文件可能在我的.gitIgnore中,并且没有提交给Jenkins。 - Dean

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接