Springが起動しなくて困っています。
すごく初歩的な質問なのかもしれませんが、数時間ネットで調べたのですが解決せず、こちらで質問させていただきます。
よろしくお願いします。
やりたいこと
-
RestContorollerからサービスを呼んで標準出力したい。
-
サービスクラスには@Serviceアノテーションをつける
-
サービスクラスをimprementsしたクラスのメソッドを呼び出したい(ここで標準出力する)
標準出力に表示されるエラー内容
*************************** APPLICATION FAILED TO START *************************** Description: Field service1 in myapp.controllers.HelloController required a bean of type 'myapp.services.Service1' 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 'myapp.services.Service1' in your configuration.
パッケージ構成
ソースコード
java
1package myapp.controllers; 2 3import org.springframework.beans.factory.annotation.Autowired; 4import org.springframework.web.bind.annotation.RequestMapping; 5import org.springframework.web.bind.annotation.RequestMethod; 6import org.springframework.web.bind.annotation.RestController; 7 8import myapp.services.Service1; 9 10@RestController 11public class HelloController { 12 13 @Autowired 14 private Service1 service1; 15 16 @RequestMapping(value="/hello", method=RequestMethod.GET) 17 public void hello() { 18 service1.hello("message1"); 19 } 20 21}
java
1package myapp.services; 2 3import org.springframework.stereotype.Service; 4 5@Service 6public interface Service1 { 7 public void hello(String message); 8}
java
1package myapp.services; 2 3public class Service1Impl implements Service1 { 4 5 @Override 6 public void hello(String message) { 7 System.out.println(message); 8 } 9}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。