TIL&WIL
2023-06-21 TIL (Spring 학습, 알고리즘 문풀)
blues_jun
2023. 6. 21. 20:42
오늘 학습한 내용
- Springboot 3 학습
- 알고리즘 문풀
문제상황
'스프링부트 3 백엔드 개발자되기' 라는 책을 공부하면서 계층을 나누고 실행을 하는 과정에서 다음 에러를 만났다.
Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled.
2023-06-21T11:22:18.448+09:00 ERROR 13128 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Field testService in me.jun.springbootdeveloper.TestController required a bean of type 'me.jun.springbootdeveloper.TestService' 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 'me.jun.springbootdeveloper.TestService' in your configuration.
Process finished with exit code 1
시도한 내용
처음에는 에러 내용을 읽지 않고 혹시 내배캠 강의를 들으면서 port를 8080을 쓰는데 혹시 port가 충돌해서 발생한 오류라고 생각해서 'application.yml'파일에서 포트를 변경했다.
server:
port: 8888
그래도 계속 똑같은 오류가 발생했다. (port는 문제 없었던걸로,,)
이제 에러 내용을 읽어보니 요구된 bean을 읽을 수 없다는 내용이 써져있었고, 혹시 service, repository에 에너테이션을 달지 않았나?라고 깨닫고 확인을 해보니..
예상대로 에너테이션을 달지 않았었다.
해결
Service에 @Service, Repository에 @Repository 에너테이션을 달아주니 이제 springboot가 bean으로 인식해서 문제없이 프로그램이 잘 실행되었다.
알게된 내용
코드를 작성할때 꼼꼼하게 작성하자.
에러가 발생했을 때에는 짐작해서 해결하려 하지 말고 에러 메세지를 꼼꼼하게 읽어보자.