Guest User

Untitled

a guest
Apr 3rd, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. spring.flyway.locations=classpath:db/migration/{vendor}
  2.  
  3. package com.flyway.demo.configuration;
  4.  
  5. import org.apache.commons.dbcp.BasicDataSource;
  6. import org.flywaydb.core.Flyway;
  7. import org.springframework.cache.annotation.EnableCaching;
  8. import org.springframework.context.annotation.*;
  9. import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
  10. import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
  11. import org.springframework.transaction.annotation.EnableTransactionManagement;
  12.  
  13. import javax.sql.DataSource;
  14.  
  15. /**
  16. * @author ftaher
  17. * @since 4/2/2018
  18. */
  19.  
  20. @Configuration
  21. @Profile("mysql")
  22. @EnableJpaRepositories(basePackages = "com.flyway.demo")
  23. @EnableJpaAuditing
  24. @EnableTransactionManagement(proxyTargetClass = true)
  25. @EnableCaching
  26. public class FlywayConfigurationSQL {
  27.  
  28. @Bean(name = "flyway")
  29. @DependsOn(value = "dataSource")
  30. public Flyway flyWay() {
  31. Flyway flyway = new Flyway();
  32. flyway.setDataSource(dataSource());
  33. flyway.setBaselineVersionAsString("0");
  34. flyway.setBaselineOnMigrate(true);
  35. flyway.setSchemas("test");
  36. flyway.setLocations("classpath:db/migration/{vendor}");
  37. flyway.setTable("DEMOSQL_SCHEMA_VERSION");
  38. flyway.migrate();
  39.  
  40. return flyway;
  41. }
  42.  
  43. @Bean(name = "dataSource")
  44. @Primary
  45. public DataSource dataSource() {
  46. BasicDataSource dataSource = new BasicDataSource();
  47. dataSource.setUrl("jdbc:mysql://localhost:3306/test");
  48. dataSource.setUsername("root");
  49. dataSource.setPassword("root");
  50. dataSource.setTestOnReturn(true);
  51. dataSource.setTestWhileIdle(true);
  52. return dataSource;
  53. }
  54.  
  55.  
  56. }
Add Comment
Please, Sign In to add comment