본문 바로가기

서버 개발

Spring Boot REST API 회원관리 - (1) 환경구성 및 "Hello" 출력

최근 업무를 하면서 회원가입 부분 관련 작업을 하게 되었다. 구현되어있는 프로젝트들을 손대다가 막상 처음부터 구성하려고 하니 구현방법에 대해 고민도 많아지고 매끄럽게 진행되지도 않은 경험을 하였다.

그래서 정리를 위한 프로젝트를 구성해보고 여건이 된다면 기능을 하나씩 추가해 보려고 한다.

 

환경 구성

  • Spring Boot 3.3.2 + MariaDB + JPA + Gradle

 

build.gradle

  • 우선 회원관리를 위해 필요할 것 같은 spring-security, jwt 등의 의존성을 추가하였다.
  • https://mvnrepository.com/ 에서 Usages가 크고 Vulnerabilities가 없는 최신 버전을 사용하였다.
dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    compileOnly 'org.projectlombok:lombok'
    developmentOnly 'org.springframework.boot:spring-boot-devtools'
    runtimeOnly 'com.mysql:mysql-connector-j'
    annotationProcessor 'org.projectlombok:lombok'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
    implementation 'org.mariadb.jdbc:mariadb-java-client:2.2.0'
    implementation 'org.springframework.security:spring-security-core:6.3.1'
    implementation 'io.jsonwebtoken:jjwt:0.12.6'
}

 

 

application.yml

  • yml의 기본정보는 다음과 같다.
server:
  port: 8088

logging:
  level:
    org.springframework: info

spring:
  application:
    name: user_test
  datasource:
    url: jdbc:mariadb://localhost:3306/test
    username: myusername
    password: mypassword
    driver-class-name: org.mariadb.jdbc.Driver
  jpa:
    hibernate:
      ddl-auto: create
    show-sql: true
    properties:
      hibernate:
        format_sql: true

 

 

"Hello" 출력

@GetMapping("/hello")
public ResponseEntity<?> hello() {
    return ResponseEntity.ok("Hello");
}

 

호출 성공

 

앞으로 회원 가입, 로그인 등의 기능을 붙여나가려고 한다.