第一步:在application.properties里面加上这三个属性,
weather.type=rain
weather.rate=serious
weather.enable=enable
第二步,测试类里面如下测试
@SpringBootTest(classes = WeatherApplication.class)
class WeatherApplicationTests implements ApplicationContextAware {
private ApplicationContext applicationContext;
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.applicationContext = applicationContext;
}
@Test
void contextLoads() {
System.out.println(applicationContext.getBean("weatherSource"));
}
预期的话,我认为是能注入这个bean实例的,这里为什么会报错呢。麻烦老师帮忙解释下