
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-validation'
compileOnly 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
runtimeOnly 'com.h2database:h2'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}
처음 접속시 DB url: jdbc:h2:~/springbootDeveloper
이후 DB url: jdbc:h2:tcp://localhost/~/springbootDeveloper
yml
spring:
datasource:
url: jdbc:h2:tcp://localhost/~/springbootDeveloper
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
lombok 세팅

Enable annotation processing 체크
devtools 세팅

Build project automatically 체크
@EnableJpaAuditing을 추가해준 뒤에 등록자, 수정자를 처리해주는 AuditorAware을 스프링 빈으로 등록해준다.
@SpringBootApplication
@EnableJpaAuditing
public class SpringbootDeveloperApplication {
public static void main(String[] args) {
SpringApplication.run(SpringbootDeveloperApplication.class, args);
}
@Bean
public AuditorAware<Long> auditorProvider() {
return new AuditorAwareImpl();
}
}
public class AuditorAwareImpl implements AuditorAware<Long> {
@Override
public Optional<Long> getCurrentAuditor() {
// security 작성 후 구현
return null;
}
}
@EntityListeners(AuditingEntityListener.class)
@MappedSuperclass
@Getter
public class BaseTimeEntity {
@CreatedDate
@Column(updatable = false)
private LocalDateTime createdDate;
@LastModifiedDate
private LocalDateTime lastModifiedDate;
}
@EntityListeners(AuditingEntityListener.class)
@MappedSuperclass
@Getter
public class BaseEntity extends BaseTimeEntity {
@CreatedBy
@Column(updatable = false)
private Long createdBy;
@LastModifiedBy
private Long lastModifiedBy;
}