Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- javaspring
- markerinterface
- annotation
- partiql
- Route53
- filterexpression
- AWS
- 개발
- compositekey
- IdClass
- Java
- secondaryindex
- awscli
- 테스트코드
- 다이나모디비
- DynamoDB
- 자바
- query
- 오류
- 스프링테스트
- Springsecurity
- awscloud
- EmbeddedId
- Spring
- MockMvc
- 로드밸런서
- 자바스프링
- 도메인
- testresttemplate
- 스프링
Archives
- Today
- Total
아장아장 개발 일기
@Component VS @Service VS @Repository 어노테이션 차이 본문
스프링 클래스를 빈등록 할때면 component, service, repository 어노테이션 중 어떤 걸 써야할지 헷갈렸습니다.
repository는 비교적 다른 두개와 구분하기 쉬웠는데, component와 service 어노테이션이 특히 헷갈리더라구요.
이번에 baeldung에서 셋의 차이를 간략하게 다룬 글을 찾아서 한번 정리해보았습니다.
@Component
1. 스프링이 관리하는 컴포넌트로 등록됨
2. 스프링은 @Component로 등록된 bean만 인식함3. @Service와 @Repository도 @Component 어노테이션을 포함하기때문에 ApplicationContext로 등록됨.
@Repository
1. 특정 persistence에 맞는 예외를 찾고 스프링의 일원화된 체크 되지 않은(unified & unchecked) 예외로 던지기 위함
2. 이를 위해 스프링은 PersistenceExceptionTranslationPostProcessor를 제공
<bean cass= "org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/>
3. 스프링 부트를 사용한다면 이미 application context에 포함되어 있음
@Service
1. 비즈니스 로직을 담고있는 빈에 표시함
2. 서비스 레이어에서 사용된다는 것을 제외하면 다른 사용 이유는 없음.
🔦 참고한 사이트
https://www.baeldung.com/spring-component-repository-service
@Component vs @Repository and @Service in Spring | Baeldung
Learn about the differences between the @Component, @Repository and @Service annotations and when to use them.
www.baeldung.com
'개발 > Spring' 카테고리의 다른 글
failed to instantiate com.fasterxml.jackson.datatype.jsr310.javatimemodule 에러 원인과 해결 방법 (0) | 2022.11.03 |
---|---|
Jar 파일 PathNotFound 오류 해결 방법 (0) | 2022.10.21 |
Spring Security ‘hasAnyAuthority()’ VS ‘hasAnyRole()’ (0) | 2022.04.21 |
Spring MockMvc 사용법 (0) | 2022.04.19 |
Spring MockMvc와 TestRestTemplate 비교 (0) | 2022.04.19 |
Comments