Skip to content

Instantly share code, notes, and snippets.

View gksxodnd007's full-sized avatar

hubert gksxodnd007

View GitHub Profile
@gksxodnd007
gksxodnd007 / querydsl.md
Created August 12, 2018 04:26
querydsl이 무엇이고 어떻게 사용하는지 알아보자.

QueryDsl이란?

  • JPQL의 빌더(Criteria)클래스

QueryDsl 사용전 설정

  • dependency 추가
dependencies {
  compile("com.querydsl:querydsl-core:4.2.1")
  compile("com.querydsl:querydsl-apt:4.2.1")
  compile("com.querydsl:querydsl-jpa:4.2.1")
@gksxodnd007
gksxodnd007 / springProperties.md
Created August 13, 2018 01:50
properties 파일 값을 읽어오는 방법

config xx.properties with Spring boot

1. @PropertySource 와 @Value를 이용한 방법

@Configuration
@PropertySource("classpath:sandbox_db.properties")
public class SandBoxDBConfig {

    @Value("${datasource.slave.driver-class-name}")
    private String driverClassName;
@gksxodnd007
gksxodnd007 / JpaTransaction.md
Created August 13, 2018 06:40
JPA 트랜잭션 롤백

Spring Data JPA에서 트랜잭션 롤백

  • 보통 spring data를 이용하면 영속성 컨텍스트의 생명주기는 트랜잭션의 유지시간과 동일함.
    • exception이 발생하여 롤백 시 트랜잭션이 닫히면서 자연스럽게 영속성 컨텍스트도 닫힌다. 문제 발생할 여지 없음
  • OSIV처럼 영속성 컨텍스트의 생명주기가 트랜잭션보다 길 때 발생 할 수 있는 문제점.
    • 데이터베이스에는 데이터가 반영되지 않았지만 영속성 컨텍스트에는 데이터가 잔류 되어있다.
    • spring frame work에서는 다음과 같은 방법으로 문제를 해결한다.
      • 트랜잭션 롤백 시 entityManager.clear()를 호출하여 영속성 컨텍스트를 초기화한다.

관련 코드

@gksxodnd007
gksxodnd007 / spring-junit4-test.md
Last active April 8, 2021 12:05
spring integration test & unit test using mockito & junit4

Junit 4 & Spring Test을 이용한 TDD 환경 세팅

  • SpringTestSupport 클래스에 설정 후 이 클래스를 상속받아 테스트를 개발함.
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = { RootContextConfig.class },
        loader = AnnotationConfigWebContextLoader.class)
@WebAppConfiguration
public class SpringTestSupport {
@gksxodnd007
gksxodnd007 / profile-default.png
Last active August 24, 2018 03:06
spring boot profile 설정
profile-default.png
@gksxodnd007
gksxodnd007 / spring-junit5-test.md
Created August 24, 2018 09:00
spring test with junit5

Junit 5 & Spring Test을 이용한 TDD 환경 세팅

기본 세팅

@ExtendWith(SpringExtension.class)
@SpringBootTest(classes = KkApplication.class)
@ActiveProfiles("test")
public abstract class SpringTestSupport {
}