如何在 Spring boot 1.4.0 中为 @DataJpaTest 排除/禁用特定的自动配置? [英] How to exclude/disable a specific auto-configuration in Spring boot 1.4.0 for @DataJpaTest?

查看:30
本文介绍了如何在 Spring boot 1.4.0 中为 @DataJpaTest 排除/禁用特定的自动配置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Spring 的 @DataJpaTest 进行测试,然后将 H2 用作内存数据库中的 此处描述.我也在使用 Flyway 进行生产.然而,一旦测试开始,FLyway 就会启动并读取 SQL 文件.如何排除 FlywayAutoConfiguration 并保持其余部分的描述 spring 文档中的此处 以便让 Hibernate 在 H2 中为我创建表?

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;
}

推荐答案

你试过 @OverrideAutoConfiguration 注释?它说它可用于覆盖 @EnableAutoConfiguration".我假设从那里你可以以某种方式排除 FlywayAutoConfiguration像这样:

Have you tried the @OverrideAutoConfiguration annotation? It says it "can be used to override @EnableAutoConfiguration". I'm assuming that from there you can somehow exclude FlywayAutoConfiguration like so:

@EnableAutoConfiguration(exclude=FlywayAutoConfiguration.class)

这篇关于如何在 Spring boot 1.4.0 中为 @DataJpaTest 排除/禁用特定的自动配置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆