rab*_*ens 7 java spring hibernate spring-mvc spring-boot
我正在使用Spring Boot和Spring Boot JPA编写一个组件.我有这样的设置:
界面:
public interface Something {
    // method definitions
}
实施:
@Component
public class SomethingImpl implements Something {
    // implementation
}
现在,我有一个运行的JUnit测试SpringJUnit4ClassRunner,我想用它测试我的SomethingImpl.
当我做
@Autowired
private Something _something;
它有效,但是
@Autowired
private SomethingImpl _something;
导致测试失败抛出一条NoSuchBeanDefinitionException消息No qualifying bean of type [com.example.SomethingImpl] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
但是在测试用例中,我想明确地注入my,SomethingImpl因为它是我想要测试的类.我怎么做到这一点?
如果你想要一个特殊的bean,你必须使用@Qualifier注释:
@Autowired
@Qualifier("SomethingImpl")
private Something _something;
| 归档时间: | 
 | 
| 查看次数: | 30038 次 | 
| 最近记录: |