2015-10-14 84 views
0

我有一个带有接口没有实现属性的数据成员的类, 如何定义这个属性?Spring定义接口没有实现的属性

我试图与@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> { 
} 
+1

您必须配置或创建一个bean。你能展示更多的代码吗? – Patrick

+0

我附上我的代码 – riv

回答

0

你有没有告诉春天你的仓库?如果SomeInterface是扩展您已经定义我认为你必须与标注的@NoRepositoryBean临时存储另一个仓库接口的存储库

//and the interface with no implementation: 
@Repository 
@Qualifier(value = "someInterface") //Should this not be someOtherRepository ??? 
public interface SomeInterface extends someRepository<AAA, String> { 
} 

:在春天引导我会做到这一点。至少在Spring引导中,请参阅此处的文档Example 7. Selectively exposing CRUD methods

+0

我添加它,但仍然不起作用。例外情况是:org.springframework.beans.factory.NoSuchBeanDefinitionException:找不到符合依赖关系的[SomeInterface]类型的合格bean:期望至少1个符合此依赖关系自动装配候选资格的bean。依赖注释:{@ org.springframework.beans.factory.annotation.Autowired(required = true)} – riv

+0

你能发布你的配置吗?你使用XML或Java配置? –

+0

和SomeRepository已经有@NoRepositoryBean注释 – riv