반응형
스프링 부츠 테스트 "형식의 적격 빈 사용 불가"
저는 스프링 부츠를 처음 신어보지만, 지금 제가 직면한 문제는 다음과 같습니다.
// Application.java
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Autowired
private Cluster cluster = null;
@PostConstruct
private void migrateCassandra() {
Database database = new Database(this.cluster, "foo");
MigrationTask migration = new MigrationTask(database, new MigrationRepository());
migration.migrate();
}
}
그래서 기본적으로 스프링 애플리케이션을 부트스트랩하고, 그 후에 카산드라 마이그레이션을 수행하려고 합니다.
사용자 모델에 대한 저장소도 정의했습니다.
// UserRepo.java
public interface UserRepo extends CassandraRepository<User> {
}
이제 다음과 같은 간단한 테스트 사례를 사용하여 repo 클래스를 테스트하려고 합니다.
// UserRepoTest.java
@RunWith(SpringRunner.class)
@AutoConfigureTestDatabase(replace = Replace.NONE)
@DataJpaTest
public class UserRepoTest {
@Autowired
private UserRepo userRepo = null;
@Autowired
private TestEntityManager entityManager = null;
@Test
public void findOne_whenUserExists_thenReturnUser() {
String id = UUID.randomUUID().toString();
User user = new User();
user.setId(id);
this.entityManager.persist(user);
assertEquals(this.userRepo.findOne(user.getId()).getId(), id);
}
@Test
public void findOne_whenUserNotExists_thenReturnNull() {
assertNull(this.userRepo.findOne(UUID.randomUUID().toString()));
}
}
테스트를 통과할 것으로 예상했지만 대신 "'com.datastax.driver.core' 유형의 한정 빈이 없습니다."라는 오류가 발생했습니다.클러스터 '사용 가능'.봄이 자동 배선에 실패한 것 같습니다.cluster물건인데 왜 그럴까요?이거 어떻게 고쳐요?정말 고마워.
테스트 환경은 콩이 어디에 정의되어 있는지 알아야 하므로 위치를 알려주어야 합니다.
테스트 클래스에서 다음을 추가합니다.@ContextConfiguration주석:
@RunWith(SpringRunner.class)
@AutoConfigureTestDatabase(replace = Replace.NONE)
@DataJpaTest
@ContextConfiguration(classes = {YourBeans.class, MoreOfYourBeans.class})
public class UserRepoTest {
@Autowired
private UserRepo userRepo = null;
@Autowired
private TestEntityManager entityManager = null;
언급URL : https://stackoverflow.com/questions/44925324/spring-boot-test-no-qualifying-bean-of-type-available
반응형
'programing' 카테고리의 다른 글
| 오류 2003(HY000):MySQL 서버에 연결할 수 없음 (111) (0) | 2023.10.02 |
|---|---|
| 각도 : ng-if 지시로 조건을 표현하는 방법? (0) | 2023.10.02 |
| 데이터 프레임을 벡터(행 단위)로 변환 (0) | 2023.10.02 |
| 테두리 스타일은 끈적거리는 위치 요소와 함께 작동하지 않습니다. (0) | 2023.09.27 |
| mmap, msync 및 linux 프로세스 종료 (0) | 2023.09.27 |