首页 > 解决方案 > “使用名称创建 bean 时出错......”它发生在 MongoRepository 的一个实例中,我使用的是 Java11 和 springboot

问题描述

我无法通过我的生活找到解决这个问题的方法xD

错误如下:


org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'itemHandler': Unsatisfied dependency expressed through field 'repo'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'itemRepository' defined in com.example.demo.service.itemRepository defined in @EnableMongoRepositories declared on MongoRepositoriesRegistrar.EnableMongoRepositoriesConfiguration: Invocation of init method failed; nested exception is org.springframework.data.mapping.PropertyReferenceException: No property findbyidItem found for type ItemObject!

如果您想查看代码,该应用程序非常小:https ://bitbucket.org/ZeroD0Z/zerod0z-api/src/master/demo/src/main/java/com/example/demo/

标签: javamongodbspring-boot

解决方案


您应该重命名您的存储库方法,正确的名称应该是大写的属性名称,(以及关键字 By 也)。所以正确的名称是(注意 IdItem):

ItemObject findByIdItem (String idItem);

否则,JPA 无法解析属性名称。


推荐阅读