私はバネの注釈を使用してコントローラでリポジトリをautowireしようとしています。私は解決策を見つけることができなかったエラーorg.springframework.data.repository.query.QueryByExampleExecutor class not found
を取得しています。私は取得しています私は春にリポジトリをautowireできません
エラー:
SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'articleController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.payforeign.article.ArticleRepository com.payforeign.article.ArticleController.repository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'articleRepository': Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: org/springframework/data/repository/query/QueryByExampleExecutor
コントローラ私は@Repository
でリポジトリを注釈を付けている
package com.payforeign.article;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
@RequestMapping("/service")
public class ArticleController {
@Autowired
private ArticleRepository repository;
//controller methods
}
リポジトリ。 Springのドキュメントによると、私はリポジトリインタフェースだけを持っています。それが正しいか?
package com.payforeign.article;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface ArticleRepository extends CrudRepository<Article, Long> {}
applicationContext.xmlを
私は正しいbase-package
とcomponent-scan
にjpa:repositories
が含まれています。私はアノテーション駆動(<mvc:annotation-driven /> <tx:annotation-driven />
)であり、JDBCとJPAの設定が追加されていると指定しました。私のapplicationContext.xmlを正しく
<context:annotation-config/>
スタックトレースがクリアです。CLASSPATHからSpring Data JARが欠落しています。 – duffymo
'NoClassDefFoundError'はほとんど常にバージョンの不一致を意味します。このケースでは、例文を得るためにRC版(または少なくとも最新版のリリース版)が必要だと思います。 – chrylis
私は 'spring-data-commons'をバージョン1.11.4から1.12.1にアップグレードし、問題を修正しました。ありがとう@chrylis – Black