2017-07-16 89 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; 
    } 
} 

重要提示:您只能在服務中使用存儲庫,並且您必須在控制器中使用該服務器