ソリューションorg.springframework.beans.factory.NoSuchBeanDefinitionExceptionに表示されます

org.springframework.beans.factory.BeanCreationException:によって引き起こされることができませんでしautowireフィールド:プライベートcn.itcast.crm.service.BaseDictService 
cn.itcast.crm.controller.CustomerController.baseDictService。ネストされた例外はorg.springframework.beans.factory.NoSuchBeanDefinitionExceptionある:いいえ[cn.itcast.crm.service.BaseDictService]が見つかったタイプの豆を修飾するための依存:期待autowire候補としての資格少なくとも1つのビーンため 、この依存性。依存注釈:{@ org.springframework.beans.factory.annotation.Autowired(=必須)} 
严重:StandardWrapper.Throwable 
org.springframework.beans.factory.BeanCreationException:名前のエラー作成ビーン「customerController」:autowired依存性の注入に失敗しました。ネストされた例外はorg.springframework.beans.factory.BeanCreationExceptionです:フィールドautowireできませんでした:プライベート cn.itcast.crm.service.BaseDictService cn.itcast.crm.controller.CustomerController.baseDictServiceを。ネストされた例外はorg.springframework.beans.factory.NoSuchBeanDefinitionExceptionある:いいえ[cn.itcast.crm.service.BaseDictService]が見つかったタイプの豆を修飾するための依存:期待autowire候補としての資格少なくとも1つのビーンため 、この依存性。依存注釈:{@ org.springframework.beans.factory.annotation.Autowired(必須= )}

問題解決のアイデア:

 

あなたは注釈設定を使用する場合は1、あなたはcn.itcast.crm.service.BaseDictServiceが実装コメント(@Serviceまたは@Componentなど)を欠落している可能性があります。

 

2.(のみ)は、XMLを使用している場合は、<豆>定義BaseDictServiceの実装を逃すかもしれません。 

 

3.コメントと実装コメントを使用している場合は、正しく、スキャンが実現チェックパッケージが配置されています

(自動コンポーネントチェックをスキャン各成分<コンテキスト:コンポーネント・スキャンベースパッケージ=「XXXX」)

または(自動春<:アノテーションのconfig /コンテキスト>スキャン)

 

4.したエラーコード:以下のような例は、

BaseDictMapperとマッパーファイルの下に、関連するmapper.xmlの構成では、サービス関連のファイルでBaseDictServiceとは、対応する設定を行うには、スプリング・コンフィギュレーション・ファイルを実行します。同じメソッド宣言とサービス実装マッパーインターフェース(しかしスプリングインターフェースとクラスマッパーフォルダスキャンしない)、したがってたBeanFactoryスプリングBeanがコンテキストで見つかりませ例は、最終的な原因は、対応するスプリングBeanを認識しませんが

パブリック インターフェースBaseDictMapper {
      // データの照会に応じてクラスコード 
      リスト<BaseDict> queryBaseDictByDictTypeCode(文字列dictTypeCode); 
 
}
パブリック インターフェースBaseDictService {
       // に従ってクエリカテゴリコード 
      一覧<BaseDict> queryBaseDictByDictTypeCode(文字列dictTypeCode); 
}
パブリック クラス BaseDictServiceImpl 実装 BaseDictMapper {     // 错误:应该实现为BaseDictService 
      @Autowired
       プライベートBaseDictMapper baseDictMapper。
      @Override 
      パブリックリスト<BaseDict> queryBaseDictByDictTypeCode(文字列dictTypeCode){ 
            リスト <BaseDict>リスト=   この.baseDictMapper.queryBaseDictByDictTypeCode(dictTypeCode)。
            戻り値のリスト。
      } 
}

5.あなたは、注射に関連付けられていることを確認依存ノートです。例えば、ダボサービスで、依存性に関連したラベルスプリング@Serviceを追加しますが、サーバーは春の必要はありませんが、@Serviceラベルのダボ。正しいですMavenの依存性を確認し、変更が下を報告し、インストールを覚えて完成されました

簡単なコード:

pom.xml

<依存性> 
        <! -春- > 
        <依存> 
            <groupIdを> org.springframework </ groupIdを> 
            <たartifactId>春・コンテキスト</たartifactId> 
        </依存関係> 
        <依存> 
            <groupIdを> org.springframework </ groupIdを> 
            <たartifactId>ばね豆</たartifactId> 
        </依存> 
        <依存性> 
            <のgroupId> org.springframework </のgroupId> 
            <たartifactId>ばねwebmvc </たartifactId> 
        </依存> 
        <依存性> 
            <のgroupId> ORG。 springframework </のgroupId> 
            <たartifactId>ばねJDBC </たartifactId> 
        </依存> 
        <依存>
            <のgroupId> org.springframework </のgroupId> 
            <たartifactId>ばね態様</たartifactId> 
        </依存> 
        <依存性> 
            <のgroupId> org.springframework </のgroupId> 
            <たartifactId>ばねJMS </たartifactId> 
        </依存> 
        <依存性> 
            <のgroupId> org.springframework </のgroupId> 
            <たartifactId>ばねコンテキストサポート</たartifactId> 
        </依存> 
        <依存性> 
            <のgroupId> org.springframework </のgroupId> 
            <たartifactId>ばね試験< /たartifactId> 
        < 
            <groupIdを> com.alibaba </ groupIdを> 
        <! -ダボ相关- >
        <依存>
            <たartifactId>ダボ</たartifactId> 
        </依存> 
        <依存性> 
            <のgroupId> org.apache.zookeeper </のgroupId> 
            <たartifactId>飼育係</たartifactId> 
        </依存> 
        <依存性> 
            <のgroupId> com.github.sgroschupf </ groupIdを> 
            <たartifactId> zkclient </たartifactId> 
        </依存関係> 
        ...
     </依存関係>

サービス:

輸入com.alibaba.dubbo.config.annotation.Service。
輸入com.chunxiansheng.mapper.TbBrandMapper;
輸入com.chunxiansheng.pojo.TbBrand;
輸入com.chunxiansheng.service.BrandService。
輸入org.springframework.beans.factory.annotation.Autowired; 
 
輸入はjava.util.List; 
 
@Service 
パブリック クラス BrandServiceImpl 実装BrandService { 
 
    @Autowired 
    プライベートTbBrandMapper brandMapper。
    ... 
}

データソース、JDBCなど何も設定ミスがありませんを確認してください6。

例えば、特定のマッパー、DAOプロファイルとdb.properties構成下ばねを表示します。

 

7. SpringBootを推奨開発に適し、操作する構成の多くを減らすことができます。

おすすめ

転載: www.cnblogs.com/qingmuchuanqi48/p/11933163.html