본문 바로가기

기타

[mac] Spring Boot 프로젝트 생성(IntelliJ)

728x90

Spring Boot 프로젝트 생성(IntelliJ)

테스트 환경

> sw_vers
ProductName:		macOS
ProductVersion:		13.1
BuildVersion:		22C65

java path 설정

vim .zshrc
export JAVA_HOME='~/Library/Java/JavaVirtualMachines/openjdk-19.0.1/Contents/Home'
export CLASSPATH='~/Library/Java/JavaVirtualMachines/openjdk-19.0.1/Contents/Home/lib'
export PATH=$PATH:$JAVA_HOME/bin
source ~/.zshrc
$ java --version
openjdk 19.0.1 2022-10-18
OpenJDK Runtime Environment (build 19.0.1+10-21)
OpenJDK 64-Bit Server VM (build 19.0.1+10-21, mixed mode, sharing)
$ echo $JAVA_HOME
~/Library/Java/JavaVirtualMachines/openjdk-19.0.1/Contents/Home

intellij idea 설치

intellij spring boot 프로젝트 생성

IntelliJ IDEA > 프로젝트 > 새 프로젝트

 

Spring Initializr

 

종속성

 

라이브러리 다운로드

 

DemoApplication.java

spring boot 실행

control + R 또는 아래 버튼으로 실행

 

 

웹 페이지 확인

"Hello World!" 출력하기

DemoApplication.java 편집

package com.example.demo;

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

@RestController
@SpringBootApplication
public class DemoApplication {
    @RequestMapping("/")
    String home() {
        return "Hello World!";
    }

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

}


build.gradle

plugins {
    id 'java'
    id 'org.springframework.boot' version '3.0.2-SNAPSHOT'
    id 'io.spring.dependency-management' version '1.1.0'
}

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

configurations {
    compileOnly {
        extendsFrom annotationProcessor
    }
}

repositories {
    mavenCentral()
    maven { url 'https://repo.spring.io/milestone' }
    maven { url 'https://repo.spring.io/snapshot' }
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-web'
    compileOnly 'org.projectlombok:lombok'
    developmentOnly 'org.springframework.boot:spring-boot-devtools'
    annotationProcessor 'org.projectlombok:lombok'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

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