Java 无法检测测试类的默认资源位置:类路径资源不存在
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23611132/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Could not detect default resource locations for test class : class path resource does not exist
提问by Dean
I am having a little issue running maven build in jenkins. It's trying to run my integration test but, keep throwing this error:
我在 jenkins 中运行 maven build 时遇到了一个小问题。它正在尝试运行我的集成测试,但是不断抛出此错误:
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']
See link for full stack trace link.
请参阅完整堆栈跟踪链接的链接。
回答by Andrei Stefan
The error is related to this part of the logs:
该错误与这部分日志有关:
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.
Basically, your test class doesn't have a configuration part (either xml or @Configuration
) that it can use to build the application context.
基本上,您的测试类没有@Configuration
可用于构建应用程序上下文的配置部分(xml 或)。
See this linkfor test configuration with xml and this onefor configuration with @Configuration
annotation.