简体   繁体   English

我在使用spring crud reprsitry时遇到问题

[英]i am facing issues in using spring crud reprositry

Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'rabbitMqController': Unsatisfied dependency expressed through field 'recordsReprositry'; 上下文初始化期间遇到异常-取消刷新尝试:org.springframework.beans.factory.UnsatisfiedDependencyException:创建名称为“ rabbitMqController”的bean时出错:通过字段“ recordsReprositry”表示的不满足的依赖关系; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.rabbitmq.config.RecordsReprositry' available: expected at least 1 bean which qualifies as autowire candidate. 嵌套的异常是org.springframework.beans.factory.NoSuchBeanDefinitionException:没有类型为'com.rabbitmq.config.RecordsReprositry'的合格bean:期望至少有1个有资格作为自动装配候选的bean。 Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} 依赖项注释:{@ org.springframework.beans.factory.annotation.Autowired(required = true)}

It looks like you are annotated interface..while you should put @repository to its implementation class. 看来您是带注释的接口。。应将@repository放入其实现类。

package com.rabbitmq.config;                                                                                  

import java.util.UUID;

import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;


@Repository
public **interface** RecordsReprositry extends CrudRepository<Records, Long>{

    public Records findById(UUID id);

}

Try JPA from spring... (DOC : http://docs.spring.io/spring-data/jpa/docs/current/reference/html/ ) 从spring尝试JPA ...(DOC: http : //docs.spring.io/spring-data/jpa/docs/current/reference/html/

Example: 例:

@Repository
public interface MyRepository extends JpaRepository<EntityName,Long> {
    // here you can write your query; example:
    EntityName findByAttribute(Type value);
    // or
    @Query("SELECT * FROM EntityName t WHERE t.ID=?1")
    EntityName findByID(Long id);
}

Then you can use this repository in service (you must use autowired) 然后,您可以在服务中使用此存储库(必须使用自动装配)

Example: 例:

@Service
public class MyService{
    @Autowired 
    private MyRepository repo;

    // here you can call in a method your query
    public EntityName example() {
        EntityName e = repo.findByID((long)1);
        return e;
    }
}

Important: the repository your must use it only in service and the service you must use it in controller 重要提示:您必须仅在服务中使用存储库,而在控制器中必须使用它的服务

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我在Java中的扫描仪类中遇到问题 - I am Facing issues in Scanner Class in java 我在显示在Eclipse,IntelliJ和Netbeans上使用JavaFX在Gluon Scene Builder中创建的GUI时遇到显示问题 - I am facing issues displaying GUI I created in Gluon Scene Builder using JavaFX on Eclipse, IntelliJ and Netbeans 我在使用这个构造函数时遇到问题 - I am facing problem in using this constructor 我正在尝试创建一个类似于 class ArrayList 中的 lastIndexOf() 的方法,但我在查找元素的最后一个索引时遇到了一些问题 - I am trying to make a method just like lastIndexOf() in class ArrayList but I am facing some issues finding the last index of an element 我在Apache Tika的POM文件中添加了Jacoco Maven插件以获得代码覆盖率。 但我正面临着这样的问题 - I am adding Jacoco Maven Plugin in POM file of Apache Tika to get the Code Coverage. But i am facing issues doing so 我在 Android 中面临 ClassNotFoundException - I am facing ClassNotFoundException in Android 使用Spring Boot在Crud中搜索 - search in crud using spring boot 我在 Firestore 数据库文档中添加了一个地图作为字段,里面有一个子字段,但我的 RecyclerView 遇到了问题 - I added a map as a field in my Firestore DB document with a sub field inside, and I am facing issues to my RecyclerView 为什么我要面对这个以及什么是工作流程 - Why am i facing this and what is workflow 我正在尝试使用提供的示例“ SendEventX509.java”发送消息,但我遇到了问题。 下面提到的Stacktrace - I am trying send message using provided sample “SendEventX509.java” but I am facing issue. Stacktrace mentioned below
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM