title: How to start H2 db TCP server within Spring Boot application and with flyway
body: <p>I use Spring Boot and H2 db with Flyway, and I want to start the H2 db tcp server upon start of my application (written in Spring Boot).</p>
  <p>So I have such <strong>application.properties</strong> file.</p>
  <pre><code>db.port=9090
  spring.datasource.url=jdbc:h2:tcp://localhost:${db.port}/./database/ifin-relax
  spring.datasource.username=sa
  spring.datasource.password=password
  spring.datasource.driver-class-name=org.h2.Driver
  
  flyway.baseline-on-migrate=true
  flyway.url=jdbc:h2:tcp://localhost:${db.port}/./database/ifin-relax
  flyway.table=SCHEMA_VERSION
  flyway.user=sa
  flyway.password=password
  </code></pre>
  <p>And also I have the following configuration class for h2 db server.</p>
  <pre><code>@Configuration
  public class H2DBServerConfiguration {
  
      @Value(&quot;${db.port}&quot;)
      private String h2DbPort;
  
      @Bean
      public Server server() throws SQLException {
          return Server.createTcpServer(&quot;-tcp&quot;, &quot;-tcpAllowOthers&quot;, &quot;-tcpPort&quot;, h2DbPort).start();
      }
  }
  </code></pre>
  <p>But when I run the application it fails with exception</p>
  <pre><code>Error creating bean with name 'flywayInitializer' defined in class path resource
  </code></pre>
  <p>It seems that flyway tries to apply migrations even before H2's TCP server was instantiated. So the question is how to postpone flyway migrations until the DB Server is started?</p>