title: Set property with wiremock random port in spring boot test
body: <p>I have a Spring Boot test that uses wiremock to mock an external service. In order to avoid conflicts with parallel builds I don't want to set a fixed port number for wiremock and would like to rely on its dynamic port configuration.</p>
  
  <p>The application uses a property (<code>external.baseUrl</code>) set in the application.yml (under src/test/resources). However I didn't find a way to programmatically override that. I've tried something like this:</p>
  
  <pre><code>    WireMockServer wireMockServer = new WireMockServer();
      wireMockServer.start();
      WireMock mockClient = new WireMock("localhost", wireMockServer.port());
      System.setProperty("external.baseUrl", "http://localhost:" + wireMockServer.port());
  </code></pre>
  
  <p>but it didn't work and the value in application.yml was used instead. All other solutions that I've looked at override the property with a static value (for example in some annotation), but I don't know the value of the wiremock port until the test is run.</p>
  
  <p><strong>Clarification:</strong></p>
  
  <p>Both spring boot and wiremock run on random ports. <em>That's fine and I know how to get the value of both ports</em>. However wiremock is supposed to mock an external service and I need to tell my application how to reach it. I do this with the <code>external.baseUrl</code> property. The value I want to set in my test depends of course on the wiremock port number. <strong>My problem is simply how to programmatically set a property in a spring boot test</strong>.</p>