栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Spring Boot:@TestPropertySource未从导入的配置加载

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Spring Boot:@TestPropertySource未从导入的配置加载

我昨天对其进行了调查,发现Spring

@TestPropertySource
仅在以下位置寻找此注释:

  • 源测试类
  • 接口是否由测试类实现
  • 此测试类别的超级赛
  • 继承的注释

AbstractTestContextBootstrapper.class
是负责该代码的部分代码:

MergedTestPropertySources mergedTestPropertySources =        TestPropertySourceUtils.buildMergedTestPropertySources(testClass);MergedContextConfiguration mergedConfig = new MergedContextConfiguration(testClass,        StringUtils.toStringArray(locations),        ClassUtils.toClassArray(classes),        ApplicationContextInitializerUtils.resolveInitializerClasses(configAttributesList),        ActiveProfilesUtils.resolveActiveProfiles(testClass),        mergedTestPropertySources.getLocations(),        mergedTestPropertySources.getProperties(),        contextCustomizers, contextLoader, cacheAwareContextLoaderDelegate, parentConfig);

该方法

TestPropertySourceUtils.buildMergedTestPropertySources(testClass)
完全负责从此批注中查找和提取位置。如您所见,Spring仅在测试类上调用它。

所以,如果你想这个外部化注释,你需要创建一个超类,并把这个注释,并

@import
在其上,或与此注释创建界面,或者创建自己的注解,将结合两个注解
@import
,并
@TestPropertySource
把它放在你的测试类。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/373930.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号