[英]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.