Inflearn コミュニティ Q&A
@Service @Repository 해주는 이유
作成
·
688
0
안녕하세요. 강의 잘 듣고 있습니다. Service 코드와 Repository 코드 관련해서 의문이 하나 있는데요. ItemServiceV1이나 JdbcTemplateItemRepository, MyBatisItemRepository 등등에 @Service랑 @Repository를 해주는 이유는 뭔지 알 수 있을까요? (JdbcTemplate, MyBatis)Config에서 새로운 ItemService와 ItemRepository를 받아서 빈으로 만들어지 거면, @Service나 @Repository는 필요 없는 게 아닌지... 혹시 다른 이유가 있으신가요?
@SpringBootApplication(scanBasePackages = "hello.itemservice.web")
그리고 이 코드 때문에 @Service랑 @Repository를 붙여도 ComponentScan 대상에 제외되기 때문에 @Service랑 @Repository가 필요없을 거 같은데 아닌가영?
spring
回答 2
1
1
yh
インストラクター
안녕하세요. 강성욱님
제가 습관적으로 붙였네요^^
@Service는 생략해도 되는데, @Repository는 필요합니다. 이것을 통해서 예외 변환이 일어나기 때문이에요.
(DB1 편 참고)
감사합니다.






안녕하세요 강사님!
같은 궁금증이 생겨 db 1편에 해당 부분을 다시 찾아보려는데 강의자료에서 @Repository 관련 내용을 찾을 수 없어 답글드립니다!