@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(); }