jpa 在哪里获取方法 userbyusername 因为我没有给出任何实现并且我也检查了内部 类

where does jpa picks up the method userbyusername as i have not given any implementation and i have checked the inner classes too

在我的 spring 引导项目中,我正在使用这个启动器 jpa 。我已经在 appliction.properties 中完成了所有与数据库相关的事情。项目运行良好。我不明白这个方法的定义在哪里。我们刚刚定义了一个抽象方法,这个方法是如何工作的?

public interface UserRepository extends JpaRepository<UserEntity, Integer>{
    
    Optional<UserEntity> getUserByUserName(String user);
}

这是 JPA 存储库的神奇之处。具体原理我也不知道,只知道怎么用

最终,我认为这与 Spring 代理接口的方式有关。 Spring 将在运行时创建接口实例。当方法按照规范命名时,Spring可以生成合适的方法。

这里有一篇很好的文章,详细介绍了如何构造方法名称来进行所需的查询:https://www.baeldung.com/spring-data-derived-queries