Excluding Spring Integration from Spring Boot Test with Spring Boot 1.4

北城余情 提交于 2019-12-08 08:33:08

问题


I've recently began using Spring Boot 1.4 and the new Spring Boot Test feature.

I'm using spring-boot-starter-integration with Spring Boot 1.4.2.RELEASE and attempting to test my repository with the new @DataJpaTest

When I run my test I get an exception about no qualifying bean. The bean in question is the handler for my integration beans.

How do I exclude integration from running during my JPA test?

Application Class:

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ImportResource;

@SpringBootApplication
@ImportResource("integration.xml")
public class AutomateResultConsumerApplication {
    public static void main(String[] args) {
        SpringApplication.run(AutomateResultConsumerApplication.class, args);
    }
}

Test Class:

@RunWith(SpringRunner.class)
@DataJpaTest
public class SampleHistoryRepositoryTest {
    @Autowired
    private TestEntityManager entityManager;

    @Autowired
    private SampleHistoryRepository sampleHistoryRepository;

    @Test
    public void findAllByObjectIdAndField() throws Exception {
        this.entityManager.persist(new SampleHistory(2L, "field", "somethingold", "somethingnew"));

        List<SampleHistory> sampleHistories = sampleHistoryRepository.findAllByObjectIdAndField(2L, "field", null);
        assertThat(sampleHistories.get(0).getOriginalValue()).isEqualTo("somethingold");
        assertThat(sampleHistories.get(0).getField()).isEqualTo("field");


    }

来源:https://stackoverflow.com/questions/41021902/excluding-spring-integration-from-spring-boot-test-with-spring-boot-1-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!