1. IntelliJ 다운로드 및 설치

 

https://www.jetbrains.com/ko-kr/idea/download

 

최고의 Java 및 Kotlin IDE인 IntelliJ IDEA를 다운로드하세요

 

www.jetbrains.com

 

 

 

 

 

2. IntelliJ 실행

 

Starter로 진행

 

 

 

 

 

3. New Project 생성 시작

 

 

 

 

 

 

4. 의존성 추가

 

5가지 선택하고 Create 클릭

 

Developer Tools -> Sptring Boot DevTools

Web -> Spring Web

Template Engines -> Mustache

SQL -> Spring Data JPA

SQL -> H2 Database

 

 

 

 

 

5. 프로젝트 실행

 

Mac의 경우 단축키는 control + r 입니다.

 

Spring Boot에서는 기본 오류 페이지로 Whitelabel Error Page를 띄워줍니다. 해당 화면이 나오면 잘 진행하고 있는 것입니다.

 

 

 

 

 

 

6. server 기본 port 변경하기

 

# server 설정

# port 설정
server.port=9999

 

 

 

 

 

7. 다른 새로운 프로젝트인 blog를 zip으로 받아서 열어보기

 

https://start.spring.io/

 

 

아래와 같이 명령어를 통해서도 위 GUI에서의 작업을 대신하여 수행할 수 있습니다. 필자는 web에서 GUI환경으로 위 절차를 진행했기에 아래 커맨드들 입력 진행이 필요하지 않습니다.

$ mkdir blog && cd blog
$ curl https://start.spring.io/starter.zip -d language=kotlin -d type=gradle-project-kotlin -d dependencies=web,mustache,jpa,h2,devtools -d packageName=com.example.blog -d name=Blog -o blog.zip

Gradle을 사용하고싶다면, 아래 문구를 추가하면 됩니다.

-d type=gradle-project

 

 

 

 

 

8. 해당 blog 프로젝트를 intelliJ IDEA에서 Open해 간단히 일부만 내용을 수정해봅니다.

 

 

// vim src/main/kotlin/com/example/blog/BlogApplication.kt

package com.example.blog

import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication

@SpringBootApplication
class BlogApplication

fun main(args: Array<String>) {
  runApplication<BlogApplication>(*args)
}

 

// vim src/main/kotlin/com/example/blog/HtmlController.kt

package com.example.blog

import org.springframework.stereotype.Controller
import org.springframework.ui.Model
import org.springframework.ui.set
import org.springframework.web.bind.annotation.GetMapping

@Controller
class HtmlController {

  @GetMapping("/")
  fun blog(model: Model): String {
    model["title"] = "Blog"
    return "blog"
  }

}

 

{{! vim src/main/resources/templates/blog.mustache }}

<html>
<head>
  <title>{{title}}</title>
</head>
<body>

 

{{! vim src/main/resources/templates/footer.mustache }}

</body>
</html>

 

{{! vim src/main/resources/templates/blog.mustache }}

<html>
<head>
  <title>{{title}}</title>
</head>
<body>

 

이렇게 동시에 2개의 Spring Boot 서버를 올려둘 수도 있습니다.

 

 

 

 

 

 

+ Recent posts