11

I've been trying to disable Flyway for my unit tests on Spring Boot 2, but could not succeed.

I understand, from Spring Boot's documentation, that the property for doing so changed from flyway.enabled to spring.flyway.enabled, and added that to my test application profile (as below).

spring:
  datasource:
    url: jdbc:h2:mem:db
  jpa:
    hibernate:
      ddl-auto: create
  flyway:
    enabled: false

This configuration appears to have no effect at all, and Flyway auto-configuration is still invoked.

I also tried creating a separate auto-configuration class for the unit tests only, where I added @EnableAutoConfiguration(exclude = FlywayAutoConfiguration.class), but this try failed as much as the previous one.

renke
  • 1,180
  • 2
  • 12
  • 27
  • Seems like that should work for all profiles, you may need to locate that under spring.profiles=test so that it only disables on testing. – mavriksc Apr 12 '18 at 19:00
  • 1
    When you try to read value of this property e.g. `@Value("${spring.flyway.enabled}")` does it print `false` in your test class? – Karol Dowbecki Apr 12 '18 at 19:08
  • @KarolDowbecki Oddly enough Spring fails to inject this or whatever other property I try to inspect, so now my suspicions are in some other configuration I might have missed. Thanks, for the question, it made me think the other way around :) – renke Apr 12 '18 at 19:34
  • 1
    @renke Property resolution should work out of the box, you must have broken something in test auto-configuration. Are you using `@SpringBootTest` and `@RunWith(SpringRunner.class)`? – Karol Dowbecki Apr 12 '18 at 19:39

3 Answers3

2

It's because you have jpa.hibernate.ddl-auto set to create. Set it to none instead. Otherwise, flyway.enabled has no effect.

Mac
  • 340
  • 1
  • 5
1

Add

spring.flyway.enabled=false

To application.properies

Alex
  • 454
  • 5
  • 5
0

I use spring-boot 2.0.3-RELEASE and add JVM option -Dspring.flyway.enabled=false

Fabio De Carli
  • 379
  • 3
  • 12