2017-07-16 1 views
1

例外コンテキストの初期化中に発生した - キャンセルリフレッシュしよう:org.springframework.beans.factory.UnsatisfiedDependencyException:エラーが「rabbitMqController」名前を持つBeanを作成:不満依存がrecordsReprositry」フィールドを通して表現';ネストされた例外はorg.springframework.beans.factory.NoSuchBeanDefinitionExceptionです: 'com.rabbitmq.config.RecordsReprositry'タイプの適格なBeanはありません。:少なくとも1つのBeanがautowire候補になります。依存関係のアノテーション:{@ org.springframework.beans.factory.annotation.Autowired(必要=真)}iは、春のクラッド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

あなたの質問を編集して追加情報を提供することができます。 @RestControllerパブリッククラスRabbitMqController { \t Autowired \tプライベートRecordsReprositry recordsReprositryをrequestmappingコントローラこれらはautowiredと注釈されているが、リポジトリコード – Andrew

答えて

0

あなたはその実装クラスに@Repository置くべきinterface..whileあなたが注釈を付けているように見えます。

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

(DOC:http://docs.spring.io/spring-data/jpa/docs/current/reference/html/)...春からJPAを試してみてください

例:次に、あなたがサービスでこのリポジトリを使用することができます

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

重要:リポジトリではサービスでのみ使用する必要があり、サービスではコントローラで使用する必要があります

関連する問題