MongoDB - 考虑在您的配置中定义一个“org.springframework.data.mongodb.repository.query.MongoEntityInformation"类型的 bean [英] MongoDB -Consider defining a bean of type 'org.springframework.data.mongodb.repository.query.MongoEntityInformation' in your configuration

查看:32
本文介绍了MongoDB - 考虑在您的配置中定义一个“org.springframework.data.mongodb.repository.query.MongoEntityInformation"类型的 bean的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的学生实体类

package com.example.entity;

import java.io.Serializable;

import javax.persistence.Id;

import org.springframework.data.mongodb.core.mapping.Document;

@Document(collection = "student")
public class StudentMongo implements Serializable {

    private static final long serialVersionUID = 8764013757545132519L;

    @Id
    private Long id;

    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

}

我的仓库

package com.example.repository;

import javax.annotation.Resource;

import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.data.mongodb.repository.query.MongoEntityInformation;
import org.springframework.data.mongodb.repository.support.SimpleMongoRepository;
import org.springframework.stereotype.Repository;

import com.example.entity.StudentMongo;

@Repository
public class StudentMongoRepository extends SimpleMongoRepository<StudentMongo, Long> {

    @Resource
    MongoOperations mongoOperations;


    public StudentMongoRepository(MongoEntityInformation<StudentMongo, Long> metadata, MongoOperations mongoOperations) {
        super(metadata, mongoOperations);
    }

}

我的配置类

@Configuration
@EnableMongoRepositories(basePackageClasses = {com.example.repository.StudentMongoRepository.class})
public class MongoConfiguration {

}

Spring 启动应用程序

Spring boot application

当我尝试启动应用程序时,我收到了以下应用程序

When i try to start the application i am getting following application

2017-11-20 09:04:48.937 ERROR 23220 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

Parameter 0 of constructor in com.example.repository.StudentMongoRepository required a bean of type 'org.springframework.data.mongodb.repository.query.MongoEntityInformation' that could not be found.


Action:

Consider defining a bean of type 'org.springframework.data.mongodb.repository.query.MongoEntityInformation' in your configuration.

考虑在你的配置中定义一个'org.springframework.data.mongodb.repository.query.MongoEntityInformation'类型的bean如何按照spring框架的说法创建EntityInformation bean运行我的应用程序时遇到上述问题.如何传递实体信息

Consider defining a bean of type 'org.springframework.data.mongodb.repository.query.MongoEntityInformation' in your configuration How to create EntityInformation bean as said by spring framework Getting above issue while running my application . how to pass entity information

建议我如何使用 SimpleMongorepository

suggest me how to use SimpleMongorepository

推荐答案

首先我想说请不要使用实现类来代替使用接口.

声明一个接口并从 MongoRepository 扩展它,spring 将提供开箱即用的实现.

declare an Interface and extend it from MongoRepository<T,ID>, spring will provide the implementation out-of-the-box.

@Repository
public interface StudentMongoRepository extends MongoRepository<T,ID>{

@Autowired
private MongoOperations mongoOperations;

这应该有效.

这篇关于MongoDB - 考虑在您的配置中定义一个“org.springframework.data.mongodb.repository.query.MongoEntityInformation"类型的 bean的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆