Taeyoung Kim

Engineering

1. 프로젝트 환경 설정 요약

1. 프로젝트 환경 설정 요약 학습 내용을 정리한 백필 노트입니다.

이 글은 2025년 학습 기록을 블로그 형식으로 정리한 백필 노트입니다.


1️⃣ 프로젝트 생성

■ 사전 준비물

  • Java 17 이상 설치 필수
  • IDE: IntelliJ IDEA 또는 Eclipse
  • 스프링 부트 버전: 3.0 이상 (JDK 17 이상 필수)

⚠️ 스프링 부트 3.x 이상을 반드시 사용해야 함.

javaxjakarta 패키지 변경이 포함됨.

생성 방법:

👉 https://start.spring.io

프로젝트 설정

  • Project: Gradle - Groovy Project
  • Spring Boot: 3.x.x
  • Language: Java
  • Packaging: Jar
  • Java: 17 또는 21
  • groupId: hello
  • artifactId: hello-spring
  • Dependencies: Spring Web, Thymeleaf

2️⃣ 스프링 부트 3.0 주의사항

  1. Java 17 이상 사용 필수
  2. javaxjakarta 패키지명 변경
    • 예시:
      • javax.persistence.Entityjakarta.persistence.Entity
      • javax.annotation.PostConstructjakarta.annotation.PostConstruct
      • javax.validationjakarta.validation
  3. H2 Database 2.1.214 이상 사용 권장

📘 참고: https://bit.ly/springboot3


3️⃣ Gradle 전체 설정 (build.gradle 예시)

plugins {
    id 'org.springframework.boot' version '2.3.1.RELEASE'
    id 'io.spring.dependency-management' version '1.0.9.RELEASE'
    id 'java'
}

group = 'hello'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    testImplementation('org.springframework.boot:spring-boot-starter-test') {
        exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
    }
}

test {
    useJUnitPlatform()
}

💡 Spring Boot 최신 정식 버전만 선택 (SNAPSHOT, M1 제외)


4️⃣ 동작 확인 및 실행 방법

  • 메인 클래스 실행 후 http://localhost:8080 접속하여 에러 페이지 확인
  • IntelliJ 실행 속도 개선
    • Preferences → Build, Execution, Deployment → Build Tools → Gradle
    • Build and run using: IntelliJ IDEA
    • Run tests using: IntelliJ IDEA

5️⃣ IntelliJ 관련 설정

■ 단축키 확인 방법 (Windows)

  • 예: Ctrl + Alt + Shift + T → Refactor This
  • 경로: File → Settings → Keymap

■ JDK 설정 확인

  • File → Project Structure (Ctrl+Alt+Shift+S)
  • Project SDK: Java 17 이상
  • Gradle JVM: Java 17 이상

6️⃣ 라이브러리 살펴보기

🔹 주요 의존성

  • spring-boot-starter-web
    • Tomcat (웹 서버)
    • Spring Web MVC
  • spring-boot-starter-thymeleaf
    • View 템플릿 엔진
  • spring-boot-starter
    • Spring Core + Logging(logback, slf4j)

🔹 테스트 관련

  • spring-boot-starter-test
    • JUnit, Mockito, AssertJ, spring-test 포함

7️⃣ View 환경 설정

■ Welcome Page 만들기

resources/static/index.html

<!DOCTYPE HTML>
<html>
<head>
  <title>Hello</title>
  <meta charset="UTF-8"/>
</head>
<body>
  Hello
  <a href="/hello">hello</a>
</body>
</html>

  • static/index.html 존재 시 자동 Welcome Page 제공

📘 Spring Boot Welcome Page 문서


8️⃣ Thymeleaf 템플릿 엔진 설정

■ Controller 예시

@Controller
public class HelloController {
    @GetMapping("hello")
    public String hello(Model model) {
        model.addAttribute("data", "hello!!");
        return "hello";
    }
}

■ View 파일 (resources/templates/hello.html)

<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
  <title>Hello</title>
  <meta charset="UTF-8"/>
</head>
<body>
  <p th:text="'안녕하세요. ' + ${data}">안녕하세요. 손님</p>
</body>
</html>

💡 spring-boot-devtools 사용 시 서버 재시작 없이 HTML 변경 반영 가능

(IntelliJ: Build → Recompile)


9️⃣ 빌드 및 실행

./gradlew build
cd build/libs
java -jar hello-spring-0.0.1-SNAPSHOT.jar

✅ 실행 확인

  • http://localhost:8080/hello 접속

💻 윈도우 사용자 팁


전체 목차 요약

  1. 프로젝트 생성
  2. 스프링 부트 3.0 주의사항
  3. Gradle 전체 설정
  4. 동작 확인
  5. IntelliJ 단축키 및 JDK 설정
  6. 라이브러리 구성
  7. View 환경설정 (Welcome Page)
  8. Thymeleaf 템플릿 엔진
  9. 빌드 및 실행