実現したいこと
技術評論社 SpringFramework超入門 第3章 のテキストの模写をしたところ、
エラーで実行できなくなってしまいました。
前提
DIコンテナのイメージをつかむため、テキスト記載通りにファイルを作成しましたが、以下のエラーとなってしまっております。
発生している問題・エラーメッセージ
*************************** APPLICATION FAILED TO START *************************** Description: Field greet in com.example.demo.DependencyInjectionSampleApplication required a bean of type 'com.example.demo.chapter03.used.Greet' that could not be found. The injection point has the following annotations: - @org.springframework.beans.factory.annotation.Autowired(required=true) Action: Consider defining a bean of type 'com.example.demo.chapter03.used.Greet' in your configuration.
該当のソースコード
Java
1package com.example.demo.chapter03.used;2 3 56public interface Greet {7 9 10 void greeting();11}
Java
1package com.example.demo.chapter03.used;2 3import org.springframework.stereotype.Component;4 5 6 89 10@Component11public class MorningGreet implements Greet {12 @Override13 public void greeting() {14 System.out.println("------------------");15 System.out.println("おはようございます!");16 System.out.println("------------------");17 }18}
Java
1package com.example.demo;2 3import org.springframework.beans.factory.annotation.Autowired;4import org.springframework.boot.SpringApplication;5import org.springframework.boot.autoconfigure.SpringBootApplication;6 7import com.example.demo.chapter03.used.Greet;8 9 1112@SpringBootApplication13public class DependencyInjectionSampleApplication {14 16 17 18 public static void main(String[] args) {19 SpringApplication.run(DependencyInjectionSampleApplication.class, args)20 .getBean(DependencyInjectionSampleApplication.class).execute();21 }22 24 25 @Autowired26 Greet greet;27 29 30 private void execute() {31 greet.greeting();32 }33}
試したこと
・ DependencyInjectionSampleApplication.javaをpackage com.example.demo.chapter03.used;と同じパッケージ配下に移動して実行
補足
テキストとeclipseのバージョンが違い、スタータ・プロジェクトを作成するときに以下テキストと差分があったこと。
テキスト: 型 Gradle
:実際 : タイプ Gradle -Groovy
0 コメント