스프링 데이터 JPA

ttaho·2023년 1월 27일

Spring

목록 보기
10/13

스프링 부트와 JPA만 사용해도 개발 생산성이 정말 많이 증가하고, 코드도 줄어들지만, 스프링 데이터 JPA를 사용하면, 리포지토리에 구현 클래스 없이 인터페이스 만으로 개발을 완료할 수 있다. 반복 개발해온 기본 CRUD 기능도 스프링 데이터 JPA가 모두 제공한다.

스프링 데이터 JPA 회원 리포지토리를 사용하도록 스프링 설정 변경

package hello.hellospring;
import hello.hellospring.repository.*;
import hello.hellospring.service.MemberService;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class SpringConfig {
 private final MemberRepository memberRepository;
 public SpringConfig(MemberRepository memberRepository) {
 this.memberRepository = memberRepository;
 }
 
 @Bean
 public MemberService memberService() {
 return new MemberService(memberRepository);
 }
 
}
  • 스프링 데이터 JPA가 SpringDataJpaMemberRepository 를 스프링 빈으로 자동 등록해준다.

스프링 데이터 JPA 제공 기능

  • 인터페이스를 통한 기본적인 CRUD
  • findByName(), findByEmail() 처럼 메서드 이름 만으로 조회 기능 제공
  • 페이징 기능 자동 제공
profile
SW Engineer

0개의 댓글