【问题标题】:SpringBoot MAVEN and MongoDB -Error creating bean with nameSpringBoot MAVEN 和 MongoDB - 使用名称创建 bean 时出错
【发布时间】:2020-11-17 00:56:56
【问题描述】:

我目前正在做一个小项目,我打算展示我数据库中的一些文档。我遇到了这个问题,springboot 将我的控制器称为 bean 。 这是我真正的豆子。

public class ProductBean {
    @Id
    private String id;
    private String reference;
    private String libelle;
    @Indexed(direction = IndexDirection.ASCENDING)
    private float price;
    private String marque;
    private int stock;
    private String image;

和我的控制器:

@RestController
@RequestMapping("/categories")
public class ProductController {

    private ProductRepository prodRepo;

    @GetMapping("/all")
    public List<ProductBean> getAll() {
     ..
    }
    @GetMapping("categories/{category}/all")
    public List<ProductBean>getAllByCategory(@PathVariable String category) {...}

我的仓库

@Repository
public interface ProductRepository extends MongoRepository<ProductBean,String> {}

错误:

org.springframework.beans.factory.UnsatisfiedDependencyException:创建文件 [E:\IntelijProj\target\classes\irisi\bdss\catalog\controllers\ProductController.class] 中定义的名称为“productController”的 bean 时出错:表示不满足的依赖关系通过构造函数参数0;嵌套异常是 org.springframework.beans.factory.BeanCreationException:在 MongoRepositoriesRegistrar.EnableMongoRepositoriesConfiguration 上声明的 @EnableMongoRepositories 中定义的 irisi.bdss.catalog.repository.ProductRepository 中创建名称为“productRepository”的 bean 时出错:调用 init 方法失败;嵌套异常是 org.springframework.data.mapping.PropertyReferenceException: No property findAll found for type ProductBean! 在 org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:798) ~[spring-beans-5.3.1.jar:5.3.1] 在 org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:228) ~[spring-beans-5.3.1.jar:5.3.1] 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1356) ~[spring-beans-5.3.1.jar:5.3.1] 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1206) ~[spring-beans-5.3.1.jar:5.3.1] 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:571) ~[spring-beans-5.3.1.jar:5.3.1] 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:531) ~[spring-beans-5.3.1.jar:5.3.1] 在 org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.1.jar:5.3.1]

感谢您的帮助。我对此感到非常沮丧。

【问题讨论】:

  • 在这个部分你尝试添加注解@Autowired private ProductRepository prodRepo;
  • 你的ProductBean是什么包?
  • @DarrenForsy 它在 com.example.app.bean 包中。
  • @hirarqi 我已经这样做了,但它仍然给我同样的错误

标签: java mongodb spring-boot model-view-controller


【解决方案1】:

这是另一个文件中的查询之一。下次不要使用@Query 格式!

【讨论】:

    猜你喜欢
    • 2018-08-16
    • 2018-01-13
    • 2017-04-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-23
    • 2021-11-18
    • 1970-01-01
    相关资源
    最近更新 更多