title: Using JdbcTemplate in Flyway's Java migration files causes dependency cycle
body: <p>Since version 6.*, Flyway supports Spring bean injection into java migration files with <code>JavaMigration</code> interface implemented. Here is my example:</p>
  
  <pre><code>@Component
  public class V1_201809261821__some_migration extends BaseJavaMigration {
  
      @Autowired
      private SomeDAO someDAO;
  
      @Override
      public void migrate(Context context) throws Exception {
          someDAO.doSomething();
      }
  }
  </code></pre>
  
  <p>When startup, it complains that:</p>
  
  <pre><code>***************************
  APPLICATION FAILED TO START
  ***************************
  
  Description:
  
  The dependencies of some of the beans in the application context form a cycle:
  
     v1_201809261821__some_migration (field private SomeDAO V1_201809261821__some_migration.someDAO)
  ┌─────┐
  |  someDAO (field private org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate someDAO.namedParameterJdbcTemplate)
  ↑     ↓
  |  flywayInitializer defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]
  ↑     ↓
  |  flyway defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]
  ↑     ↓
  |  v1_201809261821__some_migration (field private SomeDAO V1_201809261821__some_migration.someDAO)
  └─────┘
  </code></pre>
  
  <p>It seems that I can't use <code>JdbcTemplate</code> in Java migration files, <a href="https://flywaydb.org/documentation/migrations#spring" rel="noreferrer">Flyway's document</a> shows that I can construct my own <code>JdbcTemplate</code> using <code>Context</code> like:</p>
  
  <pre><code>public void migrate(Context context) {
          new JdbcTemplate(new SingleConnectionDataSource(context.getConnection(), true))
                  .execute("INSERT INTO test_user (name) VALUES ('Obelix')");
  }
  </code></pre>
  
  <p>But unfortunately I have no control of <code>SomeDAO</code>, it's from another module I can't touch.</p>
  
  <p>Related versions:</p>
  
  <ul>
  <li><p>Flyway: 6.0.6</p></li>
  <li><p>Spring Boot: 2.2.0</p></li>
  </ul>