猎鹰8525
2019-02-05 22:33
@Configuration
public class StoreConfig {
@Bean
public StoreImpl store() {
return new StoreImpl();
}
}public class StoreImpl implements Store {
}
然后我在单测里面直接获取不到
@RunWith(SpringJUnit4ClassRunner.class)
@Import({StoreConfig.class})
public class StoreBaseTest {
@Resource
private StoreImpl store;
@Test
public void test(){
System.out.println(store.getClass().getName());
}
}
store 没有获取(Store store = super.getBean(“store”) 这里的store的类型应该是Store也就是接口类型 而不是实现类StoreImpl
@Bean
public Store store() {
return new StoreImpl();
}Spring入门篇
268797 学习 · 1026 问题
相似问题