我试图仅使用dataJpa层来测试我的存储库:
@DataJpaTest
@AutoConfigureTestDatabase(replace = NONE)
@RunWith(SpringRunner.class)
@ActiveProfiles("test")
public class DaoRepositoryTest extends AbstractTestWithPostgresContainer {
private static final Logger log = LoggerFactory.getLogger(DaoRepositoryTest.class);
@Autowired
private DaoRepository daoRepository;
@Test
@Sql("classpath:db/migration/V1.0__init.sql")
public void save_shouldSave() {
final Dao dao = Dao.builder()
.title("Test-title")
.build();
final Dao result = daoRepository.save(orderDao);
assertThat(result.getId()).isNotNull();
log.info("Result: {}", result);
}
}
但是我有在我的应用程序中使用过的ConfigurationProperties(我不在我的存储库测试中关心它):
@ConfigurationProperties("redirect-path")
@Data
public class PathProperties {
private Map<String, String> paths;
}
结果,我有这个异常:
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type application.config.RedirectPath' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
我认为这是因为对于DataJpaTest上下文,它不在yml中使用我的属性:
redirect-path:
paths:
test: http://localhost:8090
我怎样才能告诉Spring我不需要在测试中使用PathProperties?
现在我必须使用@SpringBootTest批注。