Spring Boot - 이메일 인증 (3) 파일 구조, gradle, yml

ysh·2023년 11월 25일
0

인턴십

목록 보기
19/25

Spring Initializr

파일 구조

  • java 파일들은 솔직히 위치는 상관없을 듯 하고 파일 구조도 개인 마다 다르니 참고로만,
    이름들도 딱히 상관 없을 듯 하다. 나중에 클래스 선언 때 맞춰서 쓰기만 하면 되니

  • ResponseDTO.java
    응답 데이터를 구조화 해놓음.

  • EmailConfig.java
    JavaMailSender, MailProperties 설정

  • AuthControllerApiV1, AuthServiceApiV1.java
    인증 코드 생성 및 전송, 검증 로직 처리 위한 컨트롤러와 서비스

  • ReqAuthenticateCodeApiV1DTO.java
    인증 코드 검증 시 요청 DTO

  • ReqSendEmailAuthenticationApiV1DTO
    인증 코드 발송 시 요청 DTO

  • EmailService
    실제 이메일 전송 로직

  • MemberAuthenticationCodeEntity, Repository
    유저 인증 코드 테이블, jpa

build.gradle

plugins {
	id 'java'
	id 'org.springframework.boot' version '3.1.6'
	id 'io.spring.dependency-management' version '1.1.4'
}

group = 'com.example'
version = '0.0.1-SNAPSHOT'

java {
	sourceCompatibility = '17'
}

configurations {
	compileOnly {
		extendsFrom annotationProcessor
	}
}

repositories {
	mavenCentral()
}

dependencies {
	// 메일 전송을 위해 추가
	implementation 'org.springframework.boot:spring-boot-starter-mail'
	// 문자열 자동 생성 함수 사용 위해 추가
	implementation 'org.apache.commons:commons-lang3:3.12.0'

	implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
	implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
	implementation 'org.springframework.boot:spring-boot-starter-web'
	compileOnly 'org.projectlombok:lombok'
	developmentOnly 'org.springframework.boot:spring-boot-devtools'
	runtimeOnly 'com.h2database:h2'
	annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
	annotationProcessor 'org.projectlombok:lombok'
	testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

tasks.named('bootBuildImage') {
	builder = 'paketobuildpacks/builder-jammy-base:latest'
}

tasks.named('test') {
	useJUnitPlatform()
}

application.yml

spring:
  thymeleaf:
    cache: false
  datasource:
    url: jdbc:h2:mem:testdb;MODE=MySQL;DB_CLOSE_DELAY=-1
    driverClassName: org.h2.Driver
    username: sa
    password:
  h2:
    console:
      enabled: true
      path: /h2
  sql:
    init:
      encoding: UTF-8
      #   schema-locations: classpath:h2/schema.sql
      # dataLocations: classpath:h2/data.sql
      mode: always
  jpa:
    defer-datasource-initialization: true
    open-in-view: false # 트랜잭션 범위 밖에서 영속성 컨텍스트를 유지할지 여부
    database-platform: org.hibernate.dialect.H2Dialect
    hibernate:
      ddl-auto: create # create-drop, update, validate, none
      naming:
        physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
        implicit-strategy: org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl
    show-sql: true
    properties:
      hibernate:
        format-sql: true
        use-sql-comments: true
        default-batch-fetch-size: 500
  servlet:
    multipart:
      max-request-size: 300MB
      max-file-size: 300MB
      
  # 메일 관련
  mail:
    host: smtp.gmail.com
    port: 587
    username: # gmail 유저 이름 (자신의 메일 주소의 @ 앞 부분)
    password: # 아까 받은 앱 비밀번호
    properties:
      mail:
        smtp:
          auth: true
          starttls:
            enable: true
            required: true
          connectiontimeout: 5000
          timeout: 5000
          writetimeout: 5000
    auth-code-expiration-millis: 1800000
profile
유승한

0개의 댓글

관련 채용 정보