Study/spring

[Spring] Annotation으로 서비스 객체 생성하기

youngine 2021. 1. 19. 10:45

서비스 객체 자체를 anotation으로 바꾸는 방법에 대해 알아보자

 

 

 

 

sevice-contex.xml

notice서비스 객체를 주석처리하면 ioc컨테이너에 담겨있는게 없기때문에

controller에서 오류가 발생한다

 

 

 

 

 

jdbcNoticeservice

jdbcNoticeService에  @component를 선언해준다.

 

 

 

 

service-context.servlet

context:component-scan base-package="webp.service"에서

@component라고 선언된 아이를 찾아 검색해서 객체를 생성해서  ioc컨테이너에 담아준다

annotaion을 이용해서 객체 생성을 위해서는 꼭 필요하다

 

 

 

 

 

 

service-context.xml

@Controller,Service,Repositry,@Component는 범용적으로 사용되는 것들인데

역할을 명확하게 구분짓기 위해서 @Service로 선언을 변경해주었다...