본문 바로가기

코드로 배우는 스프링 부트 - 인프런24

AOP AOP가 필요한 상황 모든 메소드의 호출 시간을 측정하고 싶을 때 핵심관심사항: 서비스 로직 공통관심사항: 각 서비스 로직 메소드가 얼마나 걸리는지 구한다. 직접 구하는 방법 public Long join(Member member) { // 메소드 수행시간을 구한다는 과정에서의 코드 long start = System.currentTimeMillis(); try { // 중복회원 검증 validateDuplicateMember(member); memberRepository.save(member); return member.getId(); } finally { long finish = System.currentTimeMillis(); long times = finish - start; System.out... 2022. 8. 24.
스프링 데이터 JPA 스프링 데이터 JPA는 JPA를 편리하게 사용하도록 도와주는 기술이기 때문에 먼저 JPA를 먼저 익혀야 한다. 앞의 JPA 설정을 그대로 사용한다. SpringDataJpaMemberRepository 인터페이스 생성 인터페이스는 다중 상속이 가능하다. 스프링 데이터 JPA사용을 위해서 JpaRepository 를 상속 받는다. JpaRepository를 사용하면 스프링 데이터 JPA가 인터페이스에 대한 구현체를 만들어서 자동으로 빈 등록 해준다. package hello.hellospring.repository; import hello.hellospring.domain.Member; import org.springframework.data.jpa.repository.JpaRepository; impor.. 2022. 8. 23.
JPA JPA는 기존의 반복코드와 SQL문을 직접 만들어준다. JPA를 사용하면, SQL과 데이터 중심의 설계에서 객체 중심의 설계를 할 수 있다. build.gradle 디펜던시 수정 - jdbc 주석 처리 and jpa 추가 // implementation 'org.springframework.boot:spring-boot-starter-jdbc' implementation 'org.springframework.boot:spring-boot-starter-data-jpa' application.properties 수정 # jpa 작성된 쿼리를 확인 할 수 있도록 설정 spring.jpa.show-sql=true # 자동 테이블 생성기능 끄기 spring.jpa.hibernate.ddl-auto=none jp.. 2022. 8. 22.
스프링 JDBC Template 환경설정은 순수 JDBC 설정과 동일하게 하면 된다. 순수 JDBC에서 작성한 반복 코드를 제거해준다. 실무에서 많이 사용된다고 한다. 공식 문서 https://docs.spring.io/spring-framework/docs/current/reference/html/data-access.html#jdbc-JdbcTemplate Data Access The Data Access Object (DAO) support in Spring is aimed at making it easy to work with data access technologies (such as JDBC, Hibernate, or JPA) in a consistent way. This lets you switch between the a.. 2022. 8. 19.
스프링 통합 테스트 JDBC를 이용하여 스프링과 DB를 연결한 후 테스트를 진행하는 코드를 작성한다. @Transactional: DB에서는 기본적으로 커밋을 해야 데이터가 최종적으로 저장되는데, 해당 어노테이션을 선언하면 자동적으로 롤백을 해주어서 테스트 데이터가 최종적으로 저장되지 않도록 해준다. 따라서, 반복적으로 같은 데이터로 테스트를 진행할 수 있다. @SpringBootTest: 스프링 컨테이너와 테스트를 함께 실행한다.-> 스프링이 실제로 구동된다. package hello.hellospring.service; import hello.hellospring.domain.Member; import hello.hellospring.repository.MemberRepository; import hello.hellos.. 2022. 8. 18.
순수 JDBC jdbc: 자바에서 DB를 연결할때 반드시 있어야 하는 것 build.gradle 파일에 아래 디펜던시를 추가 -> 빌드를 한번 진행해 주어야 한다. implementation 'org.springframework.boot:spring-boot-starter-jdbc' runtimeOnly 'com.h2database:h2' 해당 프로젝트에는 h2 DB를 연결한다. 스프링에서 DB접속 정보를 넣어준다. spring.datasource.url=jdbc:h2:tcp://localhost/~/test spring.datasource.driver-class-name=org.h2.Driver spring.datasource.username=sa 이전에는 메모리를 이용하여 사용하였는데 이번에는 JDBC를 이용한 리.. 2022. 8. 17.