<tfoot id='5vJig'></tfoot>

    1. <i id='5vJig'><tr id='5vJig'><dt id='5vJig'><q id='5vJig'><span id='5vJig'><b id='5vJig'><form id='5vJig'><ins id='5vJig'></ins><ul id='5vJig'></ul><sub id='5vJig'></sub></form><legend id='5vJig'></legend><bdo id='5vJig'><pre id='5vJig'><center id='5vJig'></center></pre></bdo></b><th id='5vJig'></th></span></q></dt></tr></i><div id='5vJig'><tfoot id='5vJig'></tfoot><dl id='5vJig'><fieldset id='5vJig'></fieldset></dl></div>
      1. <small id='5vJig'></small><noframes id='5vJig'>

        <legend id='5vJig'><style id='5vJig'><dir id='5vJig'><q id='5vJig'></q></dir></style></legend>
        • <bdo id='5vJig'></bdo><ul id='5vJig'></ul>
      2. 使用动态值覆盖 Junit Test 中的默认 Spring-Boot app

        时间:2023-10-01

        • <bdo id='vvaBz'></bdo><ul id='vvaBz'></ul>

              <small id='vvaBz'></small><noframes id='vvaBz'>

                <i id='vvaBz'><tr id='vvaBz'><dt id='vvaBz'><q id='vvaBz'><span id='vvaBz'><b id='vvaBz'><form id='vvaBz'><ins id='vvaBz'></ins><ul id='vvaBz'></ul><sub id='vvaBz'></sub></form><legend id='vvaBz'></legend><bdo id='vvaBz'><pre id='vvaBz'><center id='vvaBz'></center></pre></bdo></b><th id='vvaBz'></th></span></q></dt></tr></i><div id='vvaBz'><tfoot id='vvaBz'></tfoot><dl id='vvaBz'><fieldset id='vvaBz'></fieldset></dl></div>

                    <tbody id='vvaBz'></tbody>
                  <legend id='vvaBz'><style id='vvaBz'><dir id='vvaBz'><q id='vvaBz'></q></dir></style></legend>

                  <tfoot id='vvaBz'></tfoot>

                  本文介绍了使用动态值覆盖 Junit Test 中的默认 Spring-Boot application.properties 设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我想在测试中覆盖 application.properties 中定义的属性,但 @TestPropertySource 只允许提供预定义的值.

                  I want to override properties defined in application.properties in tests, but @TestPropertySource only allows to provide predefined values.

                  我需要在随机端口 N 上启动服务器,然后将此端口传递给 spring-boot 应用程序.端口必须是临时的,以允许同时在同一主机上运行多个测试.

                  What I need is to start a server on a random port N, then pass this port to spring-boot application. The port has to be ephemeral to allow running multiple tests on the same host at the same time.

                  我不是指嵌入式http服务器(jetty),而是在测试开始时启动的一些不同的服务器(例如zookeeper)并且被测试的应用程序必须连接到它.

                  I don't mean the embedded http server (jetty), but some different server that is started at the beginning of the test (e.g. zookeeper) and the application being tested has to connect to it.

                  实现这一目标的最佳方法是什么?

                  What's the best way to achieve this?

                  (这是一个类似的问题,但答案没有提到临时端口的解决方案 - 在 Junit 测试中覆盖默认 Spring-Boot application.properties 设置)

                  (here's a similar question, but answers do not mention a solution for ephemeral ports - Override default Spring-Boot application.properties settings in Junit Test)

                  推荐答案

                  从 Spring Framework 5.2.5 和 Spring Boot 2.2.6 开始,您可以在测试中使用 Dynamic Properties:

                  As of Spring Framework 5.2.5 and Spring Boot 2.2.6 you can use Dynamic Properties in tests:

                  @DynamicPropertySource
                  static void dynamicProperties(DynamicPropertyRegistry registry) {
                      registry.add("property.name", "value");
                  }
                  

                  这篇关于使用动态值覆盖 Junit Test 中的默认 Spring-Boot application.properties 设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:与 PhantomJS 等效的 Java 是什么? 下一篇:如何将特定键绑定到 Eclipse 中的不同启动配置?

                  相关文章

                  最新文章

                    <tfoot id='9Qwo2'></tfoot>

                    <small id='9Qwo2'></small><noframes id='9Qwo2'>

                    <i id='9Qwo2'><tr id='9Qwo2'><dt id='9Qwo2'><q id='9Qwo2'><span id='9Qwo2'><b id='9Qwo2'><form id='9Qwo2'><ins id='9Qwo2'></ins><ul id='9Qwo2'></ul><sub id='9Qwo2'></sub></form><legend id='9Qwo2'></legend><bdo id='9Qwo2'><pre id='9Qwo2'><center id='9Qwo2'></center></pre></bdo></b><th id='9Qwo2'></th></span></q></dt></tr></i><div id='9Qwo2'><tfoot id='9Qwo2'></tfoot><dl id='9Qwo2'><fieldset id='9Qwo2'></fieldset></dl></div>
                      <legend id='9Qwo2'><style id='9Qwo2'><dir id='9Qwo2'><q id='9Qwo2'></q></dir></style></legend>
                        <bdo id='9Qwo2'></bdo><ul id='9Qwo2'></ul>