title: Spring boot with flyway - use a dynamic db password
body: <p>I want to integrate flyway in my spring boot project, however i cannot write the password to the database in the properties file.</p>
  
  <p>with my normal datasource i use the following code</p>
  
  <pre><code>@Configuration
  @Slf4j
  public class SwatDataBaseConfig {
  
      @Value("${swat.decrypt.location}")
      private String fileLocation;
  
      @Value("${swat.datasource.url}")
      private String dbURL;
  
      @Value("${swat.datasource.driver-class-name}")
      private String driverName;
  
      @Value("${swat.datasource.username}")
      private String userName;
  
      @Value("${swat.datasource.password}")
      private String hashedPassword;
  
      @Bean
      public DataSource primaryDataSource() {
          // String password = encryptor.decrypt(hashedPassword);
          // log.debug("password is: " + password);
          String password = null;;
          Process process = null;
          try {
              process = new ProcessBuilder(fileLocation, hashedPassword).start();
          } catch (IOException e) {
              log.error("Could not read the file", e);
              return null;
          }
          InputStream is = process.getInputStream();
          InputStreamReader isr = new InputStreamReader(is);
          BufferedReader br = new BufferedReader(isr);
          String line;
          try {
              while ((line = br.readLine()) != null) {
                  password = line;
                  try {
                      password = line.split(" ")[1].trim();
                  }catch(Exception ex) {
                      log.error("Error while sanitating the password", ex);
                  }
              }
          } catch (IOException e) {
              log.error("Could not process the file output", e);
          }
          PoolProperties poolProperties = new PoolProperties();
          poolProperties.setUrl(dbURL);         
          poolProperties.setUsername(userName);            
          poolProperties.setPassword(password);
          poolProperties.setDriverClassName(driverName);
          poolProperties.setTestOnBorrow(true);
          poolProperties.setValidationQuery("SELECT 1");
          poolProperties.setValidationInterval(0);
          DataSource ds = new org.apache.tomcat.jdbc.pool.DataSource(poolProperties);
          process.destroy();
          return ds;
         // return DataSourceBuilder.create().url(dbURL).driverClassName(driverName).username(userName).password(password).build();
      }
  </code></pre>
  
  <p>this takes my encrypted password from the properties, decrypts it and than passes it to the database,
  In all the flyway examples i've seen , the password is written as plain text in the flyway properties file</p>
  
  <p>How can i configure it the way i'm using the primary datasource</p>