주요 특징은 Java17 기반의 Maven Project이고 Spring Boot DevTools, Lombok, Spring Web, Thymeleaf, Spring Security, H2 Database, Spring Data JPA를 사용한다.
application.yml 편집
spring data jpa와 h2, mustache 사용을 위한 yml 파일을 다음과 같이 작성해보자.
logging:
level:
root: info
pattern:
console: '%clr(%d{HH:mm:ss} [%-5p] [%c{20}.%M.%L] %m%n)'spring:
output:
ansi:
enabled: always
jpa:
hibernate:
ddl-auto: validate # 실행 시 테이블 자동 생성 설정
mustache:
suffix: .htmlservlet:
expose-session-attributes: true
expose-request-attributes: truedatasource:
url: jdbc:h2:~/spring_security
driver-class-name: org.h2.Driverusername: dodingpassword: 1234server:
servlet:
encoding:
force: true
---
spring:
config:
activate:
on-profile:
- devjpa:
hibernate:
ddl-auto: create # 실행 시 테이블 자동 생성 설정
properties:
hibernate:
'[format_sql]': true # 출력되는 sql을 보기 좋게 format 할 것인가?
show-sql: trueh2:
console:
enabled: true # 웹 console을 통해 h2db에 접속할 것인가?
path: /h2-console # 웹 console의 접속 경로
logging:
level:
'[com.doding]': trace'[org.hibernate.orm.jdbc.bind]': trace
---
spring:
config:
activate:
on-profile:
- testdatasource:
url: jdbc:h2:mem:testdb;DB_CLOSE_ON_EXIT=TRUE # 개별 테스트 종료 시 DB 자동 종료
driver-class-name: org.h2.Driverjpa:
hibernate:
ddl-auto: create # 실행 시 테이블 자동 생성
logging:
level:
'[com.doding]': trace'[org.hibernate.orm.jdbc.bind]': trace # 실행되는 sql에 전달되는 파라미터 출력
InMemoryUserDetailsManager는 UserDetailsService 타입의 빈으로 inmemory 기반으로 사용자명은 user, 비밀번호는 generatedPassword를 이용하도록 구성된다. 참고로이 빈은 @ConditionalOnMissingBean에 의해 제공되는 UserDetailsService가 없을 때 구성된다.
인증과 관련된 이벤트 처리를 위해 AuthenticationEventPublisher를 빈으로 구성한다. 역시 @ConditionalOnMissingBean이 선언되어있다.
@EnableWebSecurity
Spring Security의 설정 파일에는 @EnableWebSecurity를 선언해준다.