Spring Data Jpa 异常:PropertyReferenceException: No property xx for type yy
2017-10-13 19:57
811 查看
今天在写完一个仓储层方法时,tomcat启动就抛出了一个异常,内容是:
nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'xxxRepository': Invocation of init method failed; nested exception is
org.springframework.data.mapping.PropertyReferenceException: No property xx found for type yy!
定义的接口和实现类大致为:
public interface OrderRepository extends JpaRepository<Order, Long>{
Pager<Order> getList(int pageSize, int pageNo);
}
public class OrderRepositoryImpl{
Pager<Order> getList(int pageSize, int pageNo){
return ...;
}
}
想想平时也是这样,定义接口,然后定义约定的类,类名为接口名加上Impl后缀,这样调用方法时,Jpa可以自动调用实现类实现的方法。今天却不管用了。于是很纳闷,看起来没什么问题。这个异常,表名Jpa并没有找到我定义的类,而是把接口方法当成实体属性来判断了。为什么会找不到呢?仔细看,原来在实现类中的方法定义是从接口中拷出来的,方法使用缺省的访问权限修饰符(IDEA在定义接口中提示可以省略public)。于是想想是不是这个问题,加上修饰符public后,就不报错了。至于深层次的原因,还需要再看下,下回再做分享。
nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'xxxRepository': Invocation of init method failed; nested exception is
org.springframework.data.mapping.PropertyReferenceException: No property xx found for type yy!
定义的接口和实现类大致为:
public interface OrderRepository extends JpaRepository<Order, Long>{
Pager<Order> getList(int pageSize, int pageNo);
}
public class OrderRepositoryImpl{
Pager<Order> getList(int pageSize, int pageNo){
return ...;
}
}
想想平时也是这样,定义接口,然后定义约定的类,类名为接口名加上Impl后缀,这样调用方法时,Jpa可以自动调用实现类实现的方法。今天却不管用了。于是很纳闷,看起来没什么问题。这个异常,表名Jpa并没有找到我定义的类,而是把接口方法当成实体属性来判断了。为什么会找不到呢?仔细看,原来在实现类中的方法定义是从接口中拷出来的,方法使用缺省的访问权限修饰符(IDEA在定义接口中提示可以省略public)。于是想想是不是这个问题,加上修饰符public后,就不报错了。至于深层次的原因,还需要再看下,下回再做分享。
相关文章推荐
- Spring Data JPA 报错 :PropertyReferenceException: No property params found for type xxx!
- Spring Data JPA - “No Property Found for Type” Exception
- jpa中PropertyReferenceException: No property found for type异常原因
- org.springframework.data.mapping.PropertyReferenceException: No property created found for type
- org.springframework.data.mapping.PropertyReferenceException: No property xxxx found for type Xxxx
- Spring Data JPA 全局DAO的扩展(第一次用JPA时总是提示 另人抓狂的错误: No property find for type class )
- 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: No property foo found for type Bar
- Spring Data JPA: No property name found for type ×××
- 使用Spring Cloud微服务框架进行多个微服务整合时出现No converter found for return value of type:xxx异常信息
- springboot错误 java.lang.IllegalArgumentException:No converter found for return value of type
- 在使用Spring中jdbcTemplate的QueryForObject()方法时异常:EmptyResultDataAccessException
- 解决Invalid derived query! No property find found for type XX的问题
- org.springframework.data.mapping.PropertyReferenceException: No property name found for type User
- 另人抓狂的错误:java.lang.IllegalArgumentException: No property find found for type class
- Spring4.14 事务异常 NoUniqueBeanDefinitionException: No qualifying bean of type [....PlatformTransactionManager]
- mybatis 异常信息 org.apache.ibatis.reflection.ReflectionException: There is no getter for property named
- 解决Invalid derived query! No property find found for type XX的问题
- spring data jpa javax.el.PropertyNotFoundException