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的高级特性, 但需要一个配置声明
使用代理模式,自动生成实现类
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"/>
相关文章推荐
- org.springframework.beans.factory.BeanCreationException: Could not autowire field:
- [Spring] Could not autowire field 异常的一种可能原因
- 【问题解决】 web项目启动不了 org.springframework.beans.factory.BeanCreationException: Could not autowire field:
- 个人笔记 org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.
- 关于SpringMVC中org.springframework.beans.factory.BeanCreationException: Could not autowire field:的问题的解决
- Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: privat
- Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field
- Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field
- spring注解方式 idea报could not autowire
- spring注解方式 idea报could not autowire
- Could not autowire field: private com.xxx.dao(已解决)
- mybatis+spring boot, @Autowired 提示Could not autowire. No beans of … type found
- springboot整合mybatis mapper注入时显示could not autowire的解决
- @Autowired:【Could not autowire field:】
- IntelliJ idea在Spring配置无错误时,装配对象出现 Could not autowire. no beans of "XXX" type found
- 错误:org.springframework.orm.jpa.JpaSystemException: could not deserialize;
- [SpringMVC] Could not autowire field 异常的一种可能原因
- spring注解方式 idea报could not autowire,eclipse却没有问题
- spring注解方式 idea报could not autowire
- Could not autowire field: private com.rhyton.pems.core.service.IEnergyPlanService com.rhyton.pems.we