鉴于我有以下3豆:

@Component

public class ServiceConfig {

// This value is only available from the Spring Cloud Config Server

@Value("${example.property}")

private String exampleProperty;

public String getExampleProperty() {

return exampleProperty;

}

}

@Component

public class S1 {

int i = 1;

}

@Component

public class S2 {

@Autowired

S1 s1;

}

我希望能够运行以下测试:

@RunWith(SpringRunner.class)

@SpringBootTest

public class S2Test {

@Autowired

S2 s;

@Test

public void t2() {

System.out.println(s.s1.i);

}

}

我的问题是,因为我想单独测试S2类,因为它使用@Autowired我必须在我的测试中有一个Spring上下文,但是当Spring上下文启动时它会尝试创建包含bean的所有3个bean与@Value.由于此值仅可从Spring Cloud Config Server获得,因此无法创建上下文,从而产生错误:org.springframework.beans.factory.BeanCreationException:创建名为’serviceConfig’的bean时出错:注入自动连接的依赖项失败;嵌套异常是java.lang.IllegalArgumentException:无法在字符串值“${example.property}”中解析占位符’example.property’.

My Question is: How are properties read from Spring Cloud Config

Server handled in the application when unit tests are run, observe in

my test i dont even care about the config so I dont want to explicitly

have to set a value in my test just for the context to be started?

java测试spring cloud_java – 从Spring引导单元测试中排除Spring Cloud Config Server相关推荐

  1. Spring Cloud Config Server简介

    1.概述 在本教程中,我们将回顾Spring Cloud Config Server的基础知识. 我们将设置一个Config Server ,然后构建一个客户端应用程序 ,该客户端应用程序在启动时会消 ...

  2. Spring Cloud教程– Spring Cloud Config Server简介

    问题 SpringBoot在通过属性或YAML文件外部化配置属性方面提供了很大的灵活性. 我们还可以使用特定于配置文件的配置文件(例如application.properties , applicat ...

  3. 位置穿越服务器,编写Spring Cloud Config Server路径穿越漏洞全面检测脚本

    Spring Cloud Config Server路径穿越漏洞(CVE-2019-3799)的分析文章已经很多了,这里我不在画蛇填足.在分析该漏洞之后,发现了一些小细节,感觉对该漏洞检测还是挺有帮助 ...

  4. 为Spring Cloud Config Server配置远程git仓库

    简介 虽然在开发过程,在本地创建git仓库操作起来非常方便,但是在实际项目应用中,多个项目组需要通过一个中心服务器来共享配置,所以Spring Cloud配置中心支持远程git仓库,以使分散的项目组更 ...

  5. Spring Cloud Config Server

    spring cloud config server 官方文档 本地保存配置文件 先创建一个空项目 创建 config-server 作为Model创建 再创建 config-client 作为mod ...

  6. 第十二章:Spring Cloud Config Server 的配置

    ###1.为什么要使用config 集中管理 不通环境不通配置 运行期间动态调整配置 自动刷新 ###2.用法入门 导入pom <dependency><groupId>org ...

  7. Spring Cloud Config Server迁移节点或容器化带来的问题

    如果您跟我一样,目前正在使用Spring Cloud Config做为配置中心的话,本篇将来要描述的问题,强烈推荐了解和关注!因为这个问题目前存在于所有的版本中,还没有修复,需要注意避开或设法解决. ...

  8. spring配置xml文件_XML配置文件中的Spring配置文件

    spring配置xml文件 我的上一个博客非常简单,因为它涵盖了我从Spring 3.0.x到Spring 3.1.x的轻松升级,最后我提到可以将Spring模式升级到3.1,以利用Spring的最新 ...

  9. spring初始化在ServletContextListener实现类中获取spring注入对象

    查了好多资料,发现还是不全,干脆自己整理吧,至少保证在我的做法正确的,以免误导读者,也是给自己做个记录吧! 由于项目须要,需在ServletContextListener监听接口实现类中调用sprin ...

最新文章

  1. Django 模型查询2.3
  2. 编译Caffe-Win错误集锦
  3. MTD和 uboot中的bootargs 下属 mtdparts
  4. 帧同步和状态同步(一)
  5. 在windows下编译d-nets
  6. 使用Python和Prometheus跟踪天气
  7. eigen3.3.4安装笔记
  8. 多个客户端如何同时连接到服务器上的一个端口(例如80)? [重复]
  9. Codeforces 490F Treeland Tour(离散化 + 线段树合并)
  10. autojs之快捷键
  11. PySide从实战开始学习系列(一)认识PySide
  12. OEM信息修改工具-深度系统OEM-DIY
  13. qs计算机圣安排名,2020年QS世界大学排名圣安德鲁斯大学排名第100
  14. EAUML日拱一卒--序列图(Sequence Diagram)::生命周期
  15. 常用天气预报和资料网址
  16. 美团外卖成立骑手服务部,联合全国2200家餐厅推出骑手专属折扣餐
  17. windows中mysql服务无法启动
  18. matlab小球水平抛出,如何用Matlab制作小球自由落体运动的动画
  19. 全新UI运营级在线客服系统源码+无授权/带教程
  20. 外文翻译原文附在后面_外文翻译原文及配套译文

热门文章

  1. 深度阅读之《Mastering Go》
  2. Django视图(一)
  3. 《超低延时直播白皮书》已发布,推动直播延时降低90%以上
  4. 一不小心,我们办了场全球最 _____ 的技术大会......
  5. 客观指标VS主观质量:拨开遮挡高清视频技术的迷雾
  6. 走近5G云游戏标准制定——握住互联网世界看不见的手
  7. 【大会】延迟还能再低点吗?不能,但也能
  8. Hadoop之OutputFormat数据输出详解
  9. 大牛书单 | 迎金秋,与腾讯技术大咖共读好书
  10. 多图文帖智能封面提取方案