How to exclude/disable a specific auto-configurati

2019-04-19 05:08发布

I am using the @DataJpaTest from Spring for my test which will then use H2 as in memory database as described here . I'm also using Flyway for production. However once the test starts FLyway kicks in and reads the SQL file. How can I exclude the FlywayAutoConfiguration and keep the rest as described here in spring documentation in order to let Hibernate create the tables in H2 for me?

@RunWith(SpringRunner.class)
@DataJpaTest
public class MyRepositoryTest {

    @Autowired
    private TestEntityManager entityManager;

    @Autowired
    private MyRepository triggerRepository;
}

8条回答
劫难
2楼-- · 2019-04-19 05:59

I resolved the same issue by excluding the autoconfiguration from my application definition, i.e.

@SpringBootApplication(exclude = {FlywayAutoConfiguration.class})
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}
查看更多
放荡不羁爱自由
3楼-- · 2019-04-19 06:00

Adding the dependency on an in-memory database to my build.gradle
e.g. testRuntime "com.h2database:h2:1.4.194"

And adding flyway.enabled=false to application.properties in src/test/resources worked for me.

查看更多
登录 后发表回答