当前位置: 首页 > 知识库问答 >
问题:

SpringBoot MAVEN和MongoDB-创建带有名称的bean时出错

龙令雪
2023-03-14

我目前正在做一个小项目,计划展示数据库中的一些文档。我遇到了这个问题,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> {}

错误:

组织。springframework。豆。工厂UnsatisfiedPendencyException:创建名为“productController”的bean时出错,该bean在文件[E:\IntelijProj\target\classes\irisi\bdss\catalog\controllers\productController.class]中定义:通过构造函数参数0表示的未满足的依赖关系;嵌套的异常是org。springframework。豆。工厂BeanCreationException:创建名为“productRepository”的bean时出错,该名称在irisi中定义。BDS。目录存储库。MongorPositories注册表上声明的@EnableMongorPositories中定义的ProductRepository。EnableMongorPositoriesConfiguration:调用init方法失败;嵌套的异常是org。springframework。数据地图。PropertyReferenceException:找不到ProductBean类型的属性findAll!在org。springframework。豆。工厂支持构造器解决方案。在org上创建ArgumentArray(ConstructorResolver.java:798)~[spring-beans-5.3.1.jar:5.3.1]。springframework。豆。工厂支持构造器解决方案。autowireConstructor(ConstructorResolver.java:228)~[spring-beans-5.3.1.jar:5.3.1]位于org。springframework。豆。工厂支持AbstractAutoWireAbleBeanFactory。autowireConstructor(AbstractAutowireCapableBeanFactory.java:1356)~[spring-beans-5.3.1.jar:5.3.1]位于org。springframework。豆。工厂支持AbstractAutoWireAbleBeanFactory。createBeanInstance(AbstractAutowireCapableBeanFactory.java:1206)~[spring-beans-5.3.1.jar:5.3.1]位于org。springframework。豆。工厂支持AbstractAutoWireAbleBeanFactory。doCreateBean(AbstractAutowireCapableBeanFactory.java:571)~[spring-beans-5.3.1.jar:5.3.1]位于org。springframework。豆。工厂支持AbstractAutoWireAbleBeanFactory。createBean(AbstractAutowireCapableBeanFactory.java:531)~[spring-beans-5.3.1.jar:5.3.1]位于org。springframework。豆。工厂支持抽象工厂。lambda$doGetBean$0(AbstractBeanFactory.java:335)~[spring-beans-5.3.1.jar:5.3.1]

谢谢你的帮助。我对此很失望。

共有1个答案

邵修诚
2023-03-14

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

 类似资料:
  • 还有这个 UnsatisfiedDependencyException:创建名为“Client Service”的bean时出错:通过字段“Client Repository”表示的未满足的依赖关系;嵌套异常为org.springframework.beans.factory.nosuchbeandefinitionexception:没有“com.kopylov.repository.clien

  • 问题内容: 我将所有的XML Spring配置都转换为Java代码配置,但是由于我有一个丑陋的异常,所以我无法运行我的所有测试(它们之前都曾进行过测试): 这是我的测试课: 和我的: 我在测试课上尝试了推子,但这没用。该项目是Spring MVC项目,但是现在我仅测试服务层,所以为什么要在我的课程上放置该注释?即使有了该注释,也会出现另一个错误。那么,这里发生了什么? 问题答案: 您的配置很好,除

  • 问题内容: 我正在使用Springframework和Tomcat创建一个简单的REST服务。响应应该像{“ id”:“ 101”,“ name”:“ Ram”}之类的json中。每次运行时,出现以下错误 从这里开始,以下是我的Java代码和xml文件。 POM.xml web.xml front-controller-servlet.xml json / User.java json / Use

  • 当我尝试启动应用程序时,我得到以下消息: “不满意的依赖关系”异常:创建名称为“产品服务”的 Bean 时出错 [C:\Users\Acasa\0 SDA\0 Proiecte 实践\attentive2细节\目标\类\com\示例\attentive2细节\服务\产品服务.class]:通过构造函数参数 0 表示的不满意的依赖关系;嵌套的异常是组织.springframework.bean.fa

  • 当我试图运行我的项目时,我遇到了以下错误: 这是我的豆子: 我查看了我所有的文件,我自己似乎找不到错误,就像我在标题中所说的,我是初学者,我需要一些帮助。 预期的结果是让它运行,让我能够通过邮递员与它互动