@Component
- Spring에서 관리하는 객체임을 표사하기 위해 사용하는 가장 기본적인 어노테이션
- scan-auto-detection 과 dependency injection을 사용하기 위해서 사용되는 가장 기본 어노테이션
- 컨포넌트에 클르스들에 포괄적으로 @Component를 붙일 수 있지만, @Repository, @Service, @Controller의 역할을명시적으로 구분해서 써주는 것을 추천
@Repository
- DB에 접근하는 코드
@Service
- DB에 접근하는 코드의 repository에 위임
- 비지니스 로직과 관련된 모든 코드
@Controller
- 클라이언트로부터 요청이 들어왔을 때, dispatcherservlet이 handleradapter를 통해 컨트롤러를 찾기 위해 '컨트롤러' 역할을 한다고 명시
- Web MVC 코드에서 사용되는 어노테이션
- 해당 컨트롤러 밑에서만 @RequestMapping 어노테이션 사용 가능
'Spring > 공부' 카테고리의 다른 글
[SpringBoot] Controller에서 html return하기 (@RestController 는 반환되지 않는 이유) (0) | 2024.01.24 |
---|---|
[Spring] 생명주기 ( Life Cycle) (0) | 2024.01.16 |
[Spring] 의존객체 자동 주입 (@Autowired, @Resource, @injec 차이) (0) | 2024.01.15 |
[오류] application.xml cvc-elt.1.a: cannot find the declaration of element 'beans'. (0) | 2024.01.11 |
[오류] pom.xml 오류 cvc-elt.1.a:Cannot find the declaration of element 'project' (0) | 2024.01.11 |