ys TIL (4) 썸네일형 리스트형 Spring Boot Data Jpa 사용자 정의 Repository 만들기 스프링 데이터 JPA 리포지토리는 인터페이스만 정의하고 구현을 스프링이 하기 때문에 인터페이스의 직접 메서드를 구현하고 싶을 때 스프링 데이터 JPA가 제공하는 인터페이스의 많은 기능을 직접 구현해야한다. 따라서 사용자 정의 리포지토리를 사용해 스프링 데이터 JPA 리포지토리 인터페이스에서 querydsl을 사용해보자 PersonRepository public interface PersonRepository extends JpaRepository { } 1. PersonRepositoryCustom 인터페이스를 만든다 public interface PersonRepositoryCustom { List findAllPersonCustom(); } 2. PersonRepositoryImpl을 만들고 Pers.. querydsl 적용하기 1. build.gradle에 plugin 추가 plugins { ... //querydsl 추가 id "com.ewerk.gradle.plugins.querydsl" version "1.0.10" ... } 2. dependency 추가하기 dependencies { ... //querydsl 추가 implementation 'com.querydsl:querydsl-jpa' ... } 3. build.gradle에 아래 코드 추가 //querydsl 추가 시작 def querydslDir = "$buildDir/generated/querydsl" querydsl { jpa = true querydslSourcesDir = querydslDir } sourceSets { main.java.srcDir q.. Spring 외부 설정 파일 사용할 수 있는 외부 설정 properties YAML 환경 변수 커맨드 라인 아규먼트 프로퍼티 우선 순위 유저 홈 디렉토리에 있는 spring-boot-dev-tools.properties 테스트에 있는 @TestPropertySource @SpringBootTest 애노테이션의 properties 애트리뷰트 커맨드 라인 아규먼트 SPRING_APPLICATION_JSON (환경 변수 또는 시스템 프로티) 에 들어있는 프로퍼티 ServletConfig 파라미터 ServletContext 파라미터 java:comp/env JNDI 애트리뷰트 System.getProperties() 자바 시스템 프로퍼티 OS 환경 변수 RandomValuePropertySource JAR 밖에 있는 특정 프로파일용 app.. Spring Boot test에서 H2 In memory 설정하기 우선 설정을 위해서 src/test 에서 resources 디렉토리를 추가해 주고 application.yml도 추가해준다. 이렇게 추가된 application.yml은 test시 main directory 하위에 있는 application.yml보다 우선권을 가지게 된다. spring: datasource: url: jdbc:h2:mem:test username: sa password: driver-class-name: org.h2.Driver jpa: hibernate: ddl-auto: create properties: hibernate: format_sql: true logging: level: org.hibernate.SQL: debug application.yml을 다음과 같이 작성했다. 이제.. 이전 1 다음