【问题标题】:Could not detect default resource locations for test class : class path resource does not exist无法检测到测试类的默认资源位置:类路径资源不存在
【发布时间】:2014-05-12 14:02:01
【问题描述】:

我在 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']

查看完整堆栈跟踪链接link

【问题讨论】:

    标签: java spring maven jenkins


    【解决方案1】:

    错误与这部分日志有关:

    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 的测试配置,请参阅 this link,有关使用 @Configuration 注释的配置,请参阅 this one

    【讨论】:

    • 这不是真的,但是我的错没有显示我的实际测试,请参阅链接link。我有一个 MessageServiceImplIntegrationTest-context.xml 在与测试相同的位置,因为 spring 文档说它将加载(如果不包含在你 @ContextConfiguration 的“位置”中)以使用名称从类路径加载它测试并附加“-context.xml”。当我从我的 Eclipse 运行 Maven 测试时,它被发现并且测试通过了。当我将它部署到 jenkins 时,它运行然后它抱怨它找不到文件。
    • 你没有提到它适用于 Maven 测试。嗯,那么 Jenkins 设置有问题,可能是一些类路径配置,而不是 Spring。
    • 我认为它更有可能是类路径,但是,我怎么能检查..特别是从 Jenkins 是否可能或 STS。还有什么文件 jenkins 或 maven 用来确定类路径?我在想这个文件可能在我的 .gitIgnore 中并且没有提交给詹金斯。
    猜你喜欢
    • 2020-03-04
    • 2016-08-05
    • 2014-10-20
    • 1970-01-01
    • 2011-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-15
    相关资源
    最近更新 更多