Spring JPA Could not autowire field

報錯信息以下spring

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)}
   ui

 

緣由:this

自動註冊bean時,持久層的bean沒有生成,這個bean是一個接口,沒有實現類,這個是spring JPA的高級特性, 但須要一個配置聲明spa

使用代理模式,自動生成實現類代理

 在 Spring 配置文件中啓用掃描並自動建立代理的功能

                
 <-- 須要在 <beans> 標籤中增長對 jpa 命名空間的引用 --> 
 <jpa:repositories base-package="footmark.springdata.jpa.dao"
 entity-manager-factory-ref="entityManagerFactory" 
 transaction-manager-ref="transactionManager"/> 
相關文章
相關標籤/搜索