일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 29 | 30 |
- NoArgsConstructor
- Transactions Propagation Option
- spring @mapper
- 도커 로그 확인
- Spring JPA Specification
- spring mapper annotation
- vueslot
- AllArgsConstructor
- 자바버그수정
- docker 로그
- JpaRepository update
- doker logs tail
- spring DB Connection
- spring repository
- 도커 logs
- CrudRepository update
- spring JPA DB Connection
- mapper annotationo
- JPA DB 다중 Connection
- Vue
- spring mapper
- spring JPA DB multi Connection
- 도커 컨테이너 로그
- repository annotation
- JAVA Exception 종류
- Spring
- JPA DB Connection 다중
- @Builder @NoArgsConstructor
- vuecomponent
- Data Annotation
- Today
- Total
개발을 잘하고 싶은 개발자
[Spring] @Repository는 언제 쓰나요? 본문
spring에서 쓰는 어노테이션의 종류는 매우 많다
오늘은 우선 '@Repository'
https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/stereotype/Repository.html
Repository (Spring Framework 5.3.9 API)
Indicates that an annotated class is a "Repository", originally defined by Domain-Driven Design (Evans, 2003) as "a mechanism for encapsulating storage, retrieval, and search behavior which emulates a collection of objects". Teams implementing traditional
docs.spring.io
"데이터 액세스 개체"와 같은 기존 Java EE 패턴을 구현하는 팀도 이 스테레오 타입을 DAO 클래스에 적용할 수 있지만 그렇게 하기 전에 데이터 액세스 개체와 DDD 스타일 리포지토리 간의 차이점을 이해하는 데 주의를 기울여야 합니다. 이 주석은 범용 고정관념이며 개별 팀은 의미 체계를 좁히고 적절하게 사용할 수 있습니다.
이렇게 주석이 달린 클래스 DataAccessException는 PersistenceExceptionTranslationPostProcessor. 주석이 달린 클래스는 도구, 측면 등의 목적을 위해 전체 애플리케이션 아키텍처에서의 역할에 대해서도 명확합니다. Spring 2.5부터 이 주석은 의 특수화 역할도 하며 @Component구현 클래스가 클래스 경로 스캐닝을 통해 자동 감지되도록 합니다.
https://www.journaldev.com/21460/spring-repository-annotation
Spring @Repository Annotation - JournalDev
Spring Repository Example, Spring @Repository annotation, Spring Repository vs Component, Spring Repository Tutorial, What is Spring Repository.
www.journaldev.com
Spring @Repository 주석은 클래스가 객체에 대한 저장, 검색, 검색, 업데이트 및 삭제 작업을 위한 메커니즘을 제공함을 나타내는 데 사용됩니다.
여기 이 블로그의 설명이 가장 잘 나와있는것 같다
https://jeong-pro.tistory.com/151
@Component로 다 쓰지 왜 굳이 @Repository, @Service, @Controller 등을 사용하냐면 예를 들어 @Repository는 DAO의 메서드에서 발생할 수 있는 unchecked exception들을 스프링의 DataAccessException으로 처리할 수 있기 때문이다.
또한 가독성에서도 해당 애노테이션을 갖는 클래스가 무엇을 하는지 단 번에 알 수 있다.
그리고 그렇게 작성하면 자동으로 등록되는 빈의 이름은 클래스의 첫 문자가 소문자로 바뀐 이름이 자동 적용된다.
(HomeController -> homeController)
아하!

'Backend > spring' 카테고리의 다른 글
[Spring] Transactions Propagation Option with Spring JPA (0) | 2021.08.18 |
---|---|
[Spring] @Mapper 너는 누구니? (0) | 2021.08.08 |
[Spring] JPA DB Connection 다중으로 사용하기! (0) | 2021.08.03 |
[Spring JPA] JpaRepository update업데이트 하고 싶지만 save (0) | 2021.08.02 |
[Spring] RESTful 서비스 설계 - Exception 설계한 Response 처리 (0) | 2021.07.24 |