org.springframework.data.mapping.PropertyReferenceException: No property xxxx found for type Xxxx
2017-04-08 15:38
543 查看
解决方法
解决方法详见:spring data jpa @Entity property not found exception上面大致意思
你为User实体类定义了一个UserRepository,这个UserRepository中的findByName(String name);方法是通过`name`(方法的参数位置)去查询数据。但是这个
`name`并不是User实体类的属性(
XXXis not a property of your Domain class)。(不知道小弟有没有表达清楚,没有明白的请点击这里查看原文>_<)
解决办法有两种
1、把参数名称改成实体中的属性。比如本例中User实体类中有firstname和
lastname这两属性,就可以把public User findByName(String name);方法的参数
`name`改成
firstname或
lastname。
2、也有可能是一不小心,把实体类中的属性名称写错了哦(见下图)
3、如果是使用主键进行查询的,可以这样式儿的:
这个解决方法有没有用?
为啥会出现这个错误?
好了,下面开始记录解决这个问题的经历:
事情的起因
朋友发给我一段异常信息是这样式儿的:Error creating bean with name 'customerPackageServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.fuze.erp.service.customer.ICustomerService com.fuze.erp.service.customer.impl.CustomerPackageServiceImpl.iCustomerService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'customerServiceImp': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.fuze.erp.repository.customer.CustomerRepository com.fuze.erp.service.customer.impl.CustomerServiceImp.customerRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'customerRepository': Invocation of init method failed; nested exception is org.springframework.data.mapping.PropertyReferenceException: No property customerId found for type Customer!
然后我就定位到了最后一句话: No property customerId found for type Customer!然后:
按下按钮后,百度上竟然没有相关文章。去谷歌搜了一下,我去。。竟然也没有!!几近疯狂,最后还是在谷歌中找到了线索:(最后折腾那么就的原因 是我错误的理解了报错信息)
参考
org.springframework.data.mapping.PropertyReferenceException: No property detachItem found for type FruitWorking with Spring Data Repositories
Spring Data JPA - “No Property Found for Type” Exception
Spring Data for Mongo 方法名规范介绍
相关文章推荐
- org.springframework.data.mapping.PropertyReferenceException: No property created found for type
- org.springframework.data.mapping.model.MappingException: No id property found for object of type
- Caused by: org.springframework.data.mapping.PropertyReferenceException: No property name found for t
- Spring Data JPA 报错 :PropertyReferenceException: No property params found for type xxx!
- Spring Data Jpa 异常:PropertyReferenceException: No property xx for type yy
- Caused by: org.springframework.data.mapping.PropertyReferenceException
- org.springframework.data.mapping.PropertyReferenceException: No property name found for type User
- Spring Data JPA - “No Property Found for Type” Exception
- org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.oskyhang.gbd.service.UserService] found for dependency: expected at least 1 bean which qualifies as aut
- org.springframework.web.servlet.PageNotFound noHandlerFound 警告: No mapping found for HTTP request w
- org.springframework.web.servlet.PageNotFound]-[WARN] No mapping found for HTTP request with URI [/re
- 解决:No qualifying bean of type [org.springframework.jdbc.core.JdbcTemplate] found for dependency
- [org.springframework.web.servlet.PageNotFound] - No mapping found for HTTP request with URI
- org.codehaus.jackson.map.JsonMappingException: No suitable constructor found for type [si
- org.codehaus.jackson.map.JsonMappingException: No suitable constructor found for type
- Mongodb 在update时 org.springframework.data.mapping.context.InvalidPersistentPropertyPath: No property
- Spring No qualifying bean of type [org.springframework.jdbc.core.JdbcTemplate] found for dependency
- org.springframework.web.servlet.DispatcherServlet noHandlerFound 警告: No mapping found for HTTP reque
- jpa中PropertyReferenceException: No property found for type异常原因
- Spring Data JPA: No property foo found for type Bar