[HometownBoard] 프로젝트 세팅

junghan·2023년 4월 4일
0

SpringBootProject

목록 보기
1/35
post-thumbnail

이전 대시보드 프로젝트를 할 때는 nestJS로 백엔드를 해봤기 때문에 이번에는 JAVA로 백엔드 프로젝트를 경험해보고자 새로 ShowMyCNFT라는 를 시작하려 합니다. 최종 구상은 SSO로 로그인 한 뒤, 지갑연결을 통해 본인의 NFT를 인증하고 자랑할 수 있는 CNFT갤러리 사이트를 만드는 것입니다.

  1. git 레포생성
    클러스터에서만 새로 프로젝트를 생성하여 작업하다가 로컬에서 작업을 하려다 보니 SSH키가 없어 새로 키를 생성해주었습니다.
    깃 SSH KEY 생성
    기존 폴더 깃 레포로 변경하기


  1. 인텔리제이 설치
    Jetbrain toolbox
    Jetbrain 툴박스로 인텔리제이를 설치하면 모든 제품군의 버전 관리와 JVM 옵션 등을 조정할 수 있는 이점이 있기 때문에, 툴박스를 통해 설치하였습니다.


  1. JAVA, Gradle(kotlin)으로 프로젝트 생성



  1. Gradle프로젝트를 SpringBoot 프로젝트로 변경하기

build.gradle.kts 파일을 아래와 같이 변경해줍니다.

plugins {
    java
    id("org.springframework.boot") version "3.0.5"
    id("io.spring.dependency-management") version "1.1.0"
}

group = "com.showmycnft"
version = "1.0-SNAPSHOT"


repositories {
    mavenCentral()
}

dependencies {
    implementation("org.springframework.boot:spring-boot-starter-web")
    //implementation("org.springframework.boot:spring-boot-starter-data-jpa")
    testImplementation("org.springframework.boot:spring-boot-starter-test")
    testImplementation(platform("org.junit:junit-bom:5.9.1"))
    testImplementation("org.junit.jupiter:junit-jupiter")
}

tasks.test {
    useJUnitPlatform()
}
설정 주의사항

처음에 JPA 종속성 주입을 할 경우

Consider the following:
        If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
        If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).

또는

FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':bootRun'.
Process 'command '/Library/Java/JavaVirtualMachines/jdk-19.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1

에러가 나오니 주석처리할 것

SpringBoot 공식홈페이지
SpringBoot 초기설정



  1. SDKMAN을 활용한 Gradle설치
$ curl -s "https://get.sdkman.io" | bash
$ source "/Users/Junghan/.sdkman/bin/sdkman-init.sh"
$ sdk install gradle


  1. 초기 환경 세팅 확인

Main.java파일을 변경해줍니다.

package com.showmycnft;

// Press ⇧ twice to open the Search Everywhere dialog and type `show whitespaces`,
// then press Enter. You can now see whitespace characters in your code.

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@RestController
public class Main {
    public static void main(String[] args) {
        SpringApplication.run(Main.class, args);
    }
    @GetMapping("/hello")
    public String hello(@RequestParam(value = "name", defaultValue = "World") String name) {
        return String.format("Hello %s!", name);
    }
}
PS.Depedencies가 빨간 밑줄이 뜰때
  • Gradle을 refresh 해줘야합니다.
  • 상단 메뉴바 View > Tool Windows > Gradle에 들어가면
    우측에 새로운 윈도우가 생성됩니다.
  • 여기서 프로젝트명을 우클릭하여 Refresh Gradle Dependencies를 누르고 기다리면 정상적으로 적용됩니다.


  1. 실행 후 확인
$ gradle bootRun

profile
42seoul, blockchain, web 3.0

0개의 댓글