java - “使用名称创建 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/
解决方案
您应该重命名您的存储库方法,正确的名称应该是大写的属性名称,(以及关键字 By 也)。所以正确的名称是(注意 IdItem):
ItemObject findByIdItem (String idItem);
否则,JPA 无法解析属性名称。
推荐阅读
- ruby-on-rails - Heroku 备份的 Postgres 本地恢复将日期时间字段提前 4 小时
- python - pytest中的monkeypatching boto3 s3调用
- r - emmeans 输出上的 plot.CLD 可以进行哪些自定义?
- java - Android 应用因 Android 广告 ID 政策而不断被拒绝
- excel - 如何使 Excel 中的替换函数仅在另一个 Excel 工作簿中第一次出现的单词中运行?
- python - 绑定到 tkinter 中每个键的键绑定
- mysql - 在 MySQL 中合并两个结果集
- php - 如果数组具有相同的值,如何从数组中删除索引
- sql-server - sql批量查询,只在一个header中显示结果
- javascript - 我的输入类型复选框不想显示在我的 Vue Web 应用程序中