结论先行:
在继承JpaRepository的接口中,其方法名不能与实现类有所差异,即使是包装类型的也不行。
重现过程:
1、定义接口
public interface LatentUserRepository extends JpaRepository<LatentUser, Integer> {
List<LatentStatusStat> statSpecialByStatus(Integer specialId);
}
2、定义实现接口
public List<LatentStatusStat> statSpecialByStatus(int specialId) {
//...
return null;
}
3、启动Tomcat报错,
PropertyReferenceException: No property statSpecialByStatus found for type LatentUser!
分析原因:
参数有不同,一个是Integer类型,一个是int,所以Spring在反射的时候,当成了2个不同的方法。
解决方法:
都改成int,或者都改成Integer。
本文探讨了在使用Spring框架时,接口与实现类方法参数类型不一致导致的问题。具体表现为Integer与int的区别,造成Spring无法正确进行反射调用,最终抛出PropertyReferenceException异常。文章提供了修改参数类型为统一的解决方案。
2万+

被折叠的 条评论
为什么被折叠?



