Spring   发布时间:2022-04-09  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了SpringRunner忽略应用程序属性大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

我正在尝试创建Spring集成测试,如下所示:

@RunWith(SpringRunner::class)
@ActiveProfiles(profiles = ["Test"])
@ContextConfiguration(LOCATIOns = ["classpath:**/applicationContext.xml"])
open class SimpleEntityIT {...}

applicationContact.xml包含:

    <>fig/>
    <>figured/>
    

applicationContext已加载,但似乎它被忽略了. Bean不是通过组件扫描构建的,而且application.properties完全被忽略,日志中没有提到:

 2018-01-26 20:09:26,131 DEBUG Resolved LOCATIOn pattern [classpath:**/applicationContext.xml] to resources []
 2018-01-26 20:09:26,132 DEBUG Loaded 0 bean deFinitions from LOCATIOn pattern [classpath:**/applicationContext.xml]
 2018-01-26 20:09:26,167  INFO refreshing org.springframework.context.support.GenericApplicationContext@aecb35a: startup date [Fri Jan 26 20:09:26 CET 2018]; root of context hierarchy
 2018-01-26 20:09:26,167 DEBUG Bean factory for org.springframework.context.support.GenericApplicationContext@aecb35a: org.springframework.beans.factory.support.DefaultListablebeanfactory@20d3d15a: defining beans [org.springframework.context.Annotation.internalConfigurationAnnotationProcessor,org.springframework.context.Annotation.internalAutowiredAnnotationProcessor,org.springframework.context.Annotation.internalrequiredAnnotationProcessor,org.springframework.context.Annotation.internalCommonAnnotationProcessor,org.springframework.context.Annotation.internalPersistenceAnnotationProcessor,org.springframework.context.event.internalEventListenerProcessor,org.springframework.context.event.internalEventListenerFactory]; root of factory hierarchy
 2018-01-26 20:09:26,198 DEBUG CreaTing shared instance of singleton bean 'org.springframework.context.Annotation.internalConfigurationAnnotationProcessor'
 2018-01-26 20:09:26,198 DEBUG CreaTing instance of bean 'org.springframework.context.Annotation.internalConfigurationAnnotationProcessor'
 2018-01-26 20:09:26,225 DEBUG Eagerly caching bean 'org.springframework.context.Annotation.internalConfigurationAnnotationProcessor' to allow for resolving potential circular references
 2018-01-26 20:09:26,231 DEBUG Finished creaTing instance of bean 'org.springframework.context.Annotation.internalConfigurationAnnotationProcessor'

我得不到什么?

编辑:没有构造事件组件扫描bean,但实际上没有构造bean – 甚至是由< bean="">定义的bean.在applicationContext.xml中.它的内容似乎只是被忽略了,即使它被正确找到了.

最佳答案
根据最新的评论,我相信这个问题已经解决,但即使这样,也可以快速观察和替代:

a)你没有得到错误资源的错误是因为下面的attr,我建议尽早确定问题:

忽视资源未找到=“假”

另外,您可以使用以下内容

@Propertysource(value = "xyz.properties",ignoreresourceNotFound = truE)

b)完全不相关但是:

@ActiveProfiles(profiles = ["Test"])

可以写成:

@ActiveProfiles({"Test","QA"}) 

or in your application-test.properties

spring.profiles.active=Test,QA

C)对于放置applicationContext.xml,还可以在web.xml中放置替代方法

<>figLOCATIOn

(然使用@ContextConfiguration指定确切位置的注释也完全没问题!)

最重要的是,如果您使用基于注释的配置,我会建议Spring启动:-)

希望能帮助到你!!

大佬总结

以上是大佬教程为你收集整理的SpringRunner忽略应用程序属性全部内容,希望文章能够帮你解决SpringRunner忽略应用程序属性所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。