您的位置:首页 > 编程语言 > Java开发

Spring JPA Could not autowire field

2013-10-30 15:47 316 查看
报错信息如下

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private bupt.xrh.UserRepository bupt.xrh.UserServiceImpl.userRepository; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [bupt.xrh.UserRepository] 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)}

原因:

自动注册bean时,持久层的bean没有生成,这个bean是一个接口,没有实现类,这个是spring JPA的高级特性, 但需要一个配置声明

使用代理模式,自动生成实现类

在 Spring 配置文件中启用扫描并自动创建代理的功能

<-- 需要在 <beans> 标签中增加对 jpa 命名空间的引用 -->
<jpa:repositories base-package="footmark.springdata.jpa.dao"
entity-manager-factory-ref="entityManagerFactory"
transaction-manager-ref="transactionManager"/>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐