我的数据成员类具有接口无实现的属性, 我该如何定义这个属性?
我尝试使用@Autowired
,但是当我在junit中运行它时,它会抛出异常:
org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [bean name] 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 class is :
@Service
@Component(value="someClass")
@Transactional
public class someClass implements SomeService, InitializingBean {
@Autowired
private SomeInterface someInterface ;
}
//and the interface with no implementation:
public interface SomeInterface extends CrudRepository<AAA, String> {
}
答案 0 :(得分:0)
你告诉过Spring你的存储库吗?在Spring Boot中我会这样做:
//and the interface with no implementation:
@Repository
@Qualifier(value = "someInterface") //Should this not be someOtherRepository ???
public interface SomeInterface extends someRepository<AAA, String> {
}
如果SomeInterface是扩展您已定义的另一个存储库接口的存储库,我认为您必须使用@NoRepositoryBean注释中间存储库。至少在Spring启动时,请参阅此处的文档Example 7. Selectively exposing CRUD methods