Spring Bootでサーバ起動させたいのですが起動せず困っています。
仕事ではSpringがあらかじめセットアップされているマシンを借りて作業しているのですが、この度プライベートで勉強したいと思い、Spring Bootをいじっています。
やろうと思っていることは、RestControllerにアクセスして文字列を出力するようなHello World的なプログラムです。
いじったソースは、
・AppController
・AppService
・AppServiceImpl
だけです。
かなり時間を消費してしまって、作業が滞り困っています。
ご指南いただけますでしょうか。
環境:
・macOS Mojave
・Java1.8
・Spring Tool Suite
P.S.この質問は少し前にさせて頂いたんですが、間違って自己解決してしまい、再度の質問となってます。申し訳ありません。
*************************** APPLICATION FAILED TO START *************************** Description: Field service in com.springboot.controllers.AppController required a bean of type 'com.springboot.services.AppService' 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.springboot.services.AppService' in your configuration.
java
1package com.springboot.controllers; 2 3import org.springframework.beans.factory.annotation.Autowired; 4import org.springframework.web.bind.annotation.RequestMapping; 5import org.springframework.web.bind.annotation.RestController; 6 7import com.springboot.services.AppService; 8 9@RestController 10public class AppController { 11 12 @Autowired 13 private AppService service; 14 15 @RequestMapping("/hello") 16 public void hello() { 17 service.hello(); 18 } 19}
java
1package com.springboot.services; 2 3import org.springframework.stereotype.Service; 4 5@Service 6public interface AppService { 7 8 public void hello(); 9}
java
1package com.springboot.services; 2 3public class AppServiceImpl implements AppService { 4 5 @Override 6 public void hello() { 7 System.out.println("Hello"); 8 } 9 10}
どうかよろしくお願いいたします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/03/18 09:37