私はSpringブートアプリケーションを持っています。Spring Boot @autowiredは動作しません。別のクラスのクラス
私は次のようなエラーに
org.springframework.beans.factory.BeanCreationException取得:エラー は、名前のBeanを作成する 'をbirthdayController':autowired 依存性の注入は失敗しました。入れ子になった例外は org.springframework.beans.factory.BeanCreationException:できませんでした autowireフィールド:private com.esri.birthdays.dao.BirthdayRepository com.esri.birthdays.controller.BirthdayController.repository;このため autowire候補としての資格が期待少なくとも1豆:依存見つかりタイプ[com.esri.birthdays.dao.BirthdayRepository] の無修飾ビーン:ネスト 例外はorg.springframework.beans.factory.NoSuchBeanDefinitionExceptionあります依存。依存注釈: {@ org.springframework.beans.factory.annotation.Autowired(必須=真)} org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValuesで (AutowiredAnnotationBeanPostProcessor.java:334) 〜[spring- beans-4.2.4.RELEASE.jar:4.2.4.RELEASE] 、org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214) 〜[spring-beans-4.2.4.RELEASE .jar:4.2.4.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543) 〜[spring-beans-4.2.4.RELEASE.jar:4.2.4。 RELEASE] at org.springframework.beans.factory.support.AbstractAutowir eCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) 〜[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory $ 1.getObject(AbstractBeanFactory。 Javaの:306) 〜[春豆-4.2.4.RELEASE.jar:4.2.4.RELEASE] 時または
以下は、以下の私のリポジトリクラスのコード
package com.esri.birthdays.dao;
import com.esri.birthdays.model.BirthDay;
public interface BirthdayRepository extends MongoRepository<BirthDay,String> {
public BirthDay findByFirstName(String firstName);
}
ですコントローラ。
package com.esri.birthdays.controller;
@RestController
public class BirthdayController {
@Autowired
private BirthdayRepository repository;
同じパッケージ内にある場合は機能します。理由がわからない
メインクラスはどのパッケージですか?そのコンポーネントスキャンは、リポジトリパッケージとコントローラパッケージの両方をカバーしていますか? –