私は最近、Spring Boot 1.4 と新しい Spring Boot Test 機能を使い始めました。
Spring Boot 1.4.2.RELEASE で spring-boot-starter-integration を使用しており、新しいリポジトリでリポジトリをテストしようとしています@DataJpaTest
テストを実行すると、適格な Bean がないという例外が発生します。問題の Bean は、handler
私の統合 Bean です。
JPA テスト中に統合を実行から除外するにはどうすればよいですか?
アプリケーション クラス:
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);
}
}
テスト クラス:
@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");
}