2017-07-16 91 views
1

异常情况下初始化过程中遇到 - 取消刷新尝试:org.springframework.beans.factory.UnsatisfiedDependencyException:错误创建名为“rabbitMqController”豆:不满意依赖通过现场“recordsReprositry表达“;嵌套异常是org.springframework.beans.factory.NoSuchBeanDefinitionException:没有可用的bean类型'com.rabbitmq.config.RecordsReprositry'可用:预计至少有1个bean有资格作为autowire候选者。依赖注解:{@ org.springframework.beans.factory.annotation.Autowired(必需=真)}我在使用弹簧污物reprositry面临的问题

+0

请显示您定义存储库的方式。 stacktrace不足以帮助您解决问题 – Andrew

+0

package com.rabbitmq.config; import java.util.UUID; import org.springframework.data.repository.CrudRepository; import org.springframework.stereotype.Repository; @Repository 公共接口RecordsReprositry延伸CrudRepository <记录,龙> { \t公共记录findById(UUID ID); \t } –

+0

您可以编辑您的问题以提供其他信息。粘贴控制器和存储库中的代码有 – Andrew

回答

0

它看起来像你注释interface..while你应该把@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); 

} 
0

从春天尝试JPA ...(DOC:http://docs.spring.io/spring-data/jpa/docs/current/reference/html/

例子:

@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); 
} 

然后你就可以使用这个服务库(必须使用自动装配Autowired)

示例:

@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; 
    } 
} 

重要提示:您只能在服务中使用存储库,并且您必须在控制器中使用该服务器