我在休眠状态下使用psring boot 2,postgres和Jpa。
我想测试我的一堂课
@Component
public class ExportsFacade {
private SamplesService sampleService;
private SamplesRepository sampleRepository;
@Autowired
public ExportsFacade(SamplesService sampleService, SamplesRepository sampleRepository) {
this.sampleService = sampleService;
this.sampleRepository=sampleRepository;
}
...
}
我创建了此测试
@RunWith(SpringRunner.class)
@DataJpaTest
@AutoConfigureTestDatabase(replace=Replace.NONE)
public class ExportsFacadeTest {
@Autowired
private ExportsFacade exportsFacade;
@Test
public void export() throws IOException {
exportsFacade.generateExport();
}
}
我收到此错误
org.springframework.beans.factory.UnsatisfiedDependencyException: 创建名称为'com.lcm.facade.ExportsFacadeTest'的bean时出错: 通过字段“ exportsFacade”表示不满意的依赖关系;嵌套的 例外是 org.springframework.beans.factory.NoSuchBeanDefinitionException:否 可用类型为“ com.lcm.facade.ExportsFacade”的合格Bean: 期望至少有1个符合自动装配候选条件的bean。 依赖注释: {@ org.springframework.beans.factory.annotation.Autowired(required = true)}