# spring start

## lombok 설정

`lombok.config` 파일을 프로젝트 root 디렉토리에 위치 시킨다.

```systemd
lombok.Setter.flagUsage = error
lombok.AllArgsConstructor.flagUsage = error
lombok.data.flagUsage= error
lombok.ToString.flagUsage = warning
lombok.anyConstructor.addConstructorProperties=true

# https://www.baeldung.com/lombok-configuration-system
# https://velog.io/@shinhyocheol/Lombok-%EA%B3%BC-Jackson-Deserialize-%EA%B4%80%EA%B3%84
```

* `@Setter`, `@AllArgsConstructor`, `@Data` 와 같은 lombok 기능을 제한하고 싶을 때 사용
* `@ToString` 은 warning 으로 관리할 수 있다. (순환 참조 문제가 발생할 수 있기 때문에)
* `lombok.anyConstructor.addConstructorProperties=true` : Jackson 라이브러리의 deserialize 를 도와주는 `@ConstructorProperties` 기능을 모든 생성자에 추가하는 옵션

<https://velog.io/@shinhyocheol/Lombok-%EA%B3%BC-Jackson-Deserialize-%EA%B4%80%EA%B3%84>

## Spring Data JPA

개발단계에서 쿼리를 찍어보는 설정이 중요하다.

```yaml
spring:
  datasource:
  url: jdbc:h2:tcp://localhost/~/datajpa
  username: sa
  password:
  driver-class-name: org.h2.Driver
jpa:
  hibernate:
    ddl-auto: create
  properties:
    hibernate:
#      show_sql: true
      format_sql: true
logging.level:
  org.hibernate.SQL: debug
#  org.hibernate.type: trace
```

* `show_sql: true` 옵션은 쿼리 로그 출력을 logger 가 아닌 System.out 으로 콘솔에 남긴다. (사용하지 말자)
* 쿼리 파라미터 로그를 남기기 위한 방법으로 외부 라이브러리를 사용하는 방법이 있다.
  * <https://github.com/gavlyukovskiy/spring-boot-data-source-decorator>

```gradle
implementation 'com.github.gavlyukovskiy:p6spy-spring-boot-starter:1.9.0'
```

<details>

<summary>build.gradle</summary>

```gradle
plugins {
     id ‘org.springframework.boot’ version ‘2.2.1.RELEASE’
     id ‘io.spring.dependency-management’ version ‘1.0.8.RELEASE’
     id ‘java’
}
 group = ‘study’
 version = ‘0.0.1-SNAPSHOT’
 sourceCompatibility = ‘1.8’
 configurations {
     compileOnly {
         extendsFrom annotationProcessor
     }
}
 repositories {
     mavenCentral()
}
 dependencies {
     implementation ‘org.springframework.boot:spring-boot-starter-data-jpa’
     implementation ‘org.springframework.boot:spring-boot-starter-web’
     implementation ‘com.github.gavlyukovskiy:p6spy-spring-boot-starter:1.5.7’
     compileOnly ‘org.projectlombok:lombok’
     runtimeOnly ‘com.h2database:h2’
     annotationProcessor ‘org.projectlombok:lombok’
     testImplementation(‘org.springframework.boot:spring-boot-starter-test’) {
         exclude group: ‘org.junit.vintage’, module: ‘junit-vintage-engine’
     }
}
 test {
     useJUnitPlatform()
}
```

</details>

## 멀티 모듈


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://programmer-jjy.gitbook.io/second-brain/cheat-sheet/project-getting-started/spring-start.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
