title: How to overwrite ports defined in application.properties in integration tests after testcontainer started?
body: <p>Assume I want to integration test code relying on a JPA datasource in a Spring Boot 2.x application with a PostgreSQL <code>testcontainer</code> (great tool for managing Docker containers from within test classes with one or few more lines of code). Assume further that I'm managing the ports (included in the JDBC URL) in <code>application.properties</code>, e.g.</p>
  
  <pre><code>spring.datasource.url=jdbc:postgresql://user-service-postgres:5432/user_service
  </code></pre>
  
  <p>In the integration test I create testcontainers with</p>
  
  <pre><code>@Rule
  PostgreSQLContainer postgreSQLContainer = new PostgreSQLContainer();
  </code></pre>
  
  <p>In a preparation method I can access the value I want to set for <code>spring.datasource.url</code> with</p>
  
  <pre><code>postgreSQLContainer.getJdbcUrl()
  </code></pre>
  
  <p>How to tell Spring Boot in the test to use that URL instead of the one specified in <code>application.properties</code>.</p>
  
  <p>I'd like to stick to my property files in order to minimize changes, but I'm thankful for other approaches including an explanation why they're superior or necessary as well.</p>
  
  <p>I'm using Spring Boot 2.x.</p>