我在运行我的测试类时遇到问题。我运行它后它返回“ org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 't.c.i.s.se.Sfts' available: expected single matching bean but found 2: sftsImpl,sfts
”这个异常。
这是我的测试课;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Sfta.class)
public class SftaTests {
@Autowired
ApplicationContext ac;
@Test
public void contextLoads() {
Sfts sfts= ac.getBean(Sfts.class);
assertTrue(Sfts instanceof SftsImpl);
}
}
我的其他课程就像;
public interface Sfts {
public void process();
}
@Service
@Component
public class SftsImpl implements Sfts {
@Autowired
private GlobalConfig globalConfig;
@Autowired
private Ftr ftr;
private Fc fc;
@Async
@Scheduled(initialDelayString = "${s.f.t.m}", fixedRateString = "${s.f.t.m}")
public void process() {
int hod = DateTime.now().getHourOfDay();
if (hod != 6){
fc = new Fc(globalConfig, ftr);
fc.control();
}
}
}
为什么运行测试应用程序后出现错误?