๐Ÿคท[Spring Boot] 01 IntelliJ๋กœ ์Šคํ”„๋ง๋ถ€ํŠธ ์‹œ์ž‘ํ•˜๊ธฐ

dsunniยท2020๋…„ 6์›” 18์ผ
3

spring-boot

๋ชฉ๋ก ๋ณด๊ธฐ
1/2
post-thumbnail

ใ€Œ์Šคํ”„๋ง ๋ถ€ํŠธ์™€ AW๋กœ ํ˜ผ์ž ๊ตฌํ˜„ํ•˜๋Š” ์›น ์„œ๋น„์Šคใ€๋ฅผ ๋ณด๊ณ  ๊ณต๋ถ€ํ•œ ๊ธฐ๋ก์ž…๋‹ˆ๋‹ค. (์šฐ๋‹นํƒ•ํƒ•)

๐Ÿ™Œ๐Ÿป๋ชฉํ‘œ

  • Spring Boot์— ๋Œ€ํ•œ ๊ธฐ๋ณธ ๊ฐœ๋…
  • ์ •์˜ / ์žฅ์  / ๋‹จ์ ์— ๋Œ€ํ•ด ๊ธฐ๋กํ•˜๊ณ  ๊ณต๋ถ€ํ•˜๊ธฐ
  • ์‹ค์ œ URL ์ฃผ์†Œ๋ฅผ ๊ฐ€์ง€๊ณ  CI/CD ํ™˜๊ฒฝ์„ ๊ฐ–์ถ˜ ์„œ๋น„์Šค๋ฅผ ๋งŒ๋“ค๊ธฐ

๋“ค์–ด๊ฐ€๊ธฐ ์ „

https://monkey3199.github.io/develop/spring/2019/04/14/Spring-And-SpringBoot.html

Library & Framework

๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋Š” ํŠน์ • ๊ธฐ๋Šฅ์„ ํ•˜๋Š” ์ฝ”๋“œ ๋ญ‰์น˜์ด๋‹ค. ๊ฐœ๋ฐœ์ž๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ํฌํ•จ์‹œ์ผœ ์›ํ•˜๋Š” ๊ธฐ๋Šฅ์„ ์‚ฌ์šฉํ•ด ๊ฐœ๋ฐœํ•  ์ˆ˜ ์žˆ๋‹ค.

ํ”„๋ ˆ์ž„์›Œํฌ๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ํฌํ•จํ•˜๋Š” ๊ฐœ๋…์ด๊ณ , ๊ฐœ๋ฐœ์ž๊ฐ€ ๋งŒ๋“  ์ฝ”๋“œ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.


Spring Boot & Spring Framework

Spring Framework

Spring Framework๋Š” ์ž๋ฐ” ํ”Œ๋žซํผ์„ ์œ„ํ•œ ์˜คํ”ˆ์†Œ์Šค ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ํ”„๋ ˆ์ž„์›Œํฌ๋กœ์„œ, ๋™์ ์ธ ์›น ์‚ฌ์ดํŠธ๋ฅผ ๊ฐœ๋ฐœํ•˜๊ธฐ ์œ„ํ•œ ์—ฌ๋Ÿฌ ๊ฐ€์ง€ ์„œ๋น„์Šค(ํ”„๋กœ๊ทธ๋ž˜๋ฐ ๋ฐฉ๋ฒ•)๋ฅผ ์ œ๊ณตํ•œ๋‹ค.

  • ์—ฌ๋Ÿฌ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์ œ๊ณตํ•˜๊ณ , ๊ทธ๊ฒƒ์„ ํ™œ์šฉํ•ด ๊ฐœ๋ฐœํ•œ ํ”„๋กœ์ ํŠธ๋ฅผ ๋™์ž‘์‹œํ‚จ๋‹ค.
  • ์ „์ž์ •๋ถ€ ํ‘œ์ค€ ํ”„๋ ˆ์ž„์›Œํฌ์˜ ๊ธฐ๋ฐ˜ ๊ธฐ์ˆ ๋กœ์„œ ์“ฐ์ด๊ณ  ์žˆ๋‹ค.
  • Servlet API : ๊ฐœ๋ฐœ์ž๋Š” API๋ฅผ ์ฒ˜๋ฆฌํ•  ํด๋ž˜์Šค๋ฅผ ์ •์˜ํ•˜๊ณ  ๊ทธ ํด๋ž˜์Šค๊ฐ€ Servlet API๋ฅผ ์œ„ํ•œ ํด๋ž˜์Šค์ž„์„ ์–ด๋…ธํ…Œ์ด์…˜์„ ํ™œ์šฉํ•ด ํ‘œ์‹œํ•œ๋‹ค. ์ดํ›„ ํ”„๋กœ๊ทธ๋žจ ์‹คํ–‰์‹œ API ์š”์ฒญ์ด ๋“ค์–ด์˜ค๋ฉด ์Šคํ”„๋ง์€ ํ•ด๋‹น ํด๋ž˜์Šค๋ฅผ ์ด์šฉํ•ด์„œ ์ฒ˜๋ฆฌํ•œ๋‹ค. ์ง์ ‘ Servlet ๊ฐœ๋ฐœํ•˜์ง€ ์•Š์•„๋„ ๋ฐ์ดํ„ฐ ๋ฐ”์ธ๋”ฉ ๋“ฑ์˜ ์ž‘์—…๋“ค์„ ์ž๋™์œผ๋กœ ์ฒ˜๋ฆฌํ•ด์ค€๋‹ค.
  • ์Šคํ”„๋งํ”„๋ ˆ์ž„์›Œํฌ๋Š” ์›น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๊ฐœ๋ฐœํ•˜๋Š”๋ฐ ๊ฒฐํ•ฉ๋„๋ฅผ ๋‚ฎ์ถ”๋Š” ๋ฐฉํ–ฅ์˜ ๊ฐœ๋ฐœ ๋ฐฉ๋ฒ•์„ ์ œ๊ณตํ•œ๋‹ค.

Spring Boot

Spring Boot๋Š” ์Šคํ”„๋ง ํ”„๋ ˆ์ž„์›Œํฌ๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•œ ์„ค์ •์˜ ๋งŽ์€ ๋ถ€๋ถ„์„ ์ž๋™ํ™”ํ•˜์—ฌ ์Šคํ”„๋ง์„ ํŽธํ•˜๊ฒŒ ํ™œ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ๋•๋Š”๋‹ค. ๋‚ด์žฅ๋œ Tomcat ์„œ๋ฒ„๋กœ ์‹คํ–‰ ๊ฐ€๋Šฅํ•˜๋‹ค. ์‹คํ–‰ ํ™˜๊ฒฝ์ด๋‚˜ ์˜์กด์„ฑ ๊ด€๋ฆฌ ๋“ฑ์€ ์‹ ๊ฒฝ์“ธ ํ•„์š” ์—†์ด ๋ฐ”๋กœ ์ฝ”๋”ฉ ํ›„ ์‹คํ–‰ ๊ฐ€๋Šฅํ•˜๋‹ค


ํŠน์ง•

  • POJO (Plain Old Java Object)
    • ์ผ๋ฐ˜์ ์ธ J2EE ํ”„๋ ˆ์ž„์›Œํฌ์— ๋น„ํ•ด ๊ตฌํ˜„์„ ์œ„ํ•ด ํŠน์ •ํ•œ ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ๊ตฌํ˜„ํ•˜๊ฑฐ๋‚˜ ์ƒ์†์„ ๋ฐ›์„ ํ•„์š”๊ฐ€ ์—†์–ด ๊ธฐ์กด์— ์กด์žฌํ•˜๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ๋“ฑ์„ ์ง€์›ํ•˜๊ธฐ์— ์šฉ์ดํ•˜๊ณ  ๊ฐ์ฒด๊ฐ€ ๊ฐ€๋ณ๋‹ค.
  • AOP (Aspect Oriented Programming)
    • ํŠธ๋žœ์žญ์…˜์ด๋‚˜ ๋กœ๊น…, ๋ณด์•ˆ๊ณผ ๊ฐ™์ด ์—ฌ๋Ÿฌ ๋ชจ๋“ˆ์—์„œ ๊ณตํ†ต์ ์œผ๋กœ ์‚ฌ์šฉํ•˜๋Š” ๊ธฐ๋Šฅ์˜ ๊ฒฝ์šฐ ํ•ด๋‹น ๊ธฐ๋Šฅ์„ ๋ถ„๋ฆฌํ•˜์—ฌ ๊ด€๋ฆฌํ•  ์ˆ˜ ์žˆ๋‹ค.
  • DI (Dependency Injection)
    • ๊ฐ๊ฐ์˜ ๊ณ„์ธต์ด๋‚˜ ์„œ๋น„์Šค๋“ค ๊ฐ„์— ์˜์กด์„ฑ์ด ์กด์žฌํ•  ๊ฒฝ์šฐ ํ”„๋ ˆ์ž„์›Œํฌ๊ฐ€ ์„œ๋กœ ์—ฐ๊ฒฐ์‹œ์ผœ์ค€๋‹ค.
    • @Autowired : Bean ๊ฐ์ฒด์™€ ๊ฐ™์€ ํƒ€์ž…์˜ ๊ฐ์ฒด๋ฅผ ์ฐพ์•„์„œ ์ž๋™์œผ๋กœ ์ฃผ์ž…ํ•ด์ค๋‹ˆ๋‹ค.
  • IoC (Inversion of Control)
    • ์ปจํŠธ๋กค์˜ ์ œ์–ด๊ถŒ์ด ์‚ฌ์šฉ์ž๊ฐ€ ์•„๋‹ˆ๋ผ ํ”„๋ ˆ์ž„์›Œํฌ์— ์žˆ์–ด์„œ ํ•„์š”์— ๋”ฐ๋ผ ์Šคํ”„๋ง์—์„œ ์‚ฌ์šฉ์ž์˜ ์ฝ”๋“œ๋ฅผ ํ˜ธ์ถœํ•œ๋‹ค.


์›น ์„œ๋น„์Šค ๊ตฌ์ถ•์— ํ•„์š”ํ•œ ์ง€์‹

  1. ์„œ๋น„์Šค์˜ ๊ธฐ๋Šฅ์„ ๋‹ด๋‹นํ•  ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์ง€์‹
  2. ๊ฐœ๋ฐœํ•œ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์ด ๊ตฌ๋™๋  ์„œ๋ฒ„ ์ธํ”„๋ผ ์ง€์‹

์™œ IntelliJ?

  • ๊ฐ•๋ ฅํ•œ ์ถ”์ฒœ ๊ธฐ๋Šฅ
  • ๋‹ค์–‘ํ•œ ๋ฆฌํŒฉํ† ๋ง๊ณผ ๋””๋ฒ„๊น… ๊ธฐ๋Šฅ
  • ํ”„๋กœ์ ํŠธ ์‹œ์ž‘์‹œ ์ธ๋ฑ์‹ฑ์„ ํ•˜์—ฌ ์ž์› ๋ฐ ํŒŒ์ผ๋“ค์„ ๋น ๋ฅธ ์†๋„๋กœ ์ค€๋น„


1. Spring Boot ํ”„๋กœ์ ํŠธ ์ƒ์„ฑํ•˜๊ธฐ

  • ๋นŒ๋“œ ๋„๊ตฌ : Gradle
  • JDK 1.8

Gradle โ†’ Spring Boot Project

build.gradle

buildscript {
    ext {
        springBootVersion = '2.1.7.RELEASE'
    }
    repositories {
        mavenCentral()
        jcenter()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

ํ”„๋กœ์ ํŠธ์˜ ์˜์กด์„ฑ ๊ด€๋ฆฌ๋ฅผ ์œ„ํ•œ ์„ค์ •

  • ext : build.gradle ๋‚ด ์ „์—ญ๋ณ€์ˆ˜ ์„ค์ •
    • springBootVersion : 2.1.7 RELEASE์„ ํ”Œ๋Ÿฌ๊ทธ์ธ์˜ ์˜์กด์„ฑ์œผ๋กœ ๋ฐ›๊ฒ ๋‹ค๋Š” ์˜๋ฏธ

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'

์•ž์„œ ์„ ์–ธํ•œ ํ”Œ๋Ÿฌ๊ทธ์ธ ์˜์กด์„ฑ๋“ค ์ ์šฉ ๊ฒฐ์ •

  • io.spring.dependency-management ํ”Œ๋Ÿฌ๊ทธ์ธ : ์Šคํ”„๋ง ๋ถ€ํŠธ ์˜์กด์„ฑ ๊ด€๋ฆฌ ํ”Œ๋Ÿฌ๊ทธ์ธ
  • ์ž๋ฐ”์™€ ์Šคํ”„๋ง ๋ถ€ํŠธ ์‚ฌ์šฉ์„ ์œ„ํ•œ ํ•„์ˆ˜ ํ”Œ๋Ÿฌ๊ทธ์ธ๋“ค

repositories {
    mavenCentral()
    jcenter()
}

repositories๋Š” ๊ฐ์ข… ์˜์กด์„ฑ (๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ)๋“ค์„ ์–ด๋–ค ์›๊ฒฉ ์ €์žฅ์†Œ์—์„œ ๋ฐ›์„์ง€ ์ •ํ•จ

  • ๊ธฐ๋ณธ : mavenCentral
    • BUT ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์—…๋ฐ์ดํŠธ ๋‚œ์ด๋„๋กœ ์ธํ•ด ์ตœ๊ทผ์—๋Š” jcenter ๋งŽ์ด ์‚ฌ์šฉํ•จ
    • ์ง์ ‘ ๋งŒ๋“  ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์—…๋กœ๋“œ์‹œ ๋ฌธ์ œ์ , ์–ด๋ ค์›€ ๅคš
  • jcenter
    • ๊ฐ„๋‹จํ•œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์—…๋กœ๋“œ
    • jecenter์— ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์—…๋กœ๋“œ์‹œ mavenCentral์—๋„ ์ž๋™์ ์œผ๋กœ ์—…๋กœ๋“œ๋จ

dependencies {
    compile('org.springframework.boot:spring-boot-starter-web')
    testCompile group: 'junit', name: 'junit', version: '4.12'
}

dependencies๋Š” ํ”„๋กœ๊ทธ๋žจ ๊ฐœ๋ฐœ์— ํ•„์š”ํ•œ ์˜์กด์„ฑ๋“ค ์„ ์–ธํ•˜๋Š” ๊ณณ

  • intelliJsms ๋ฉ”์ด๋ธ ์ €์žฅ์†Œ์˜ ๋ฐ์ดํ„ฐ๋ฅผ ์ธ๋ฑ์‹ฑํ•ด์„œ ๊ด€๋ฆฌํ•˜๊ธฐ์— ์ปค๋ฎค๋‹ˆํ‹ฐ ๋ฒ„์ „์„ ์‚ฌ์šฉํ•ด๋„ ์˜์กด์„ฑ ์ž๋™์™„์„ฑ์ด ๊ฐ€๋Šฅํ•จ

  • ํŠน์ • ๋ฒ„์ „์„ ๋ช…์‹œํ•˜์ง€ ์•Š์•„์•ผ์ง€ ์œ„์˜ "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}"๋ฒ„์ „์„ ๋”ฐ๋ผ๊ฐ

  • ์žฅ์ 

    • ๊ฐ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์˜ ๋ฒ„์ „ ๊ด€๋ฆฌ์˜ ์ง‘์ค‘
    • ๋ฒ„์ „ ์ถฉ๋Œ ๋ฌธ์ œ์˜ ํ•ด๊ฒฐ
  • Enable auto import : Gradle ์„ค์ • ์ž๋™ ๋ฐ˜์˜

build.gradle

buildscript {
    ext {
        springBootVersion = '2.1.7.RELEASE'
    }
    repositories {
        mavenCentral()
        jcenter()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

plugins {
    id 'java'
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'

group 'com.studying.book'
version '1.0-SNAPSHOT'

sourceCompatibility = 1.8


repositories {
    mavenCentral()
    jcenter()
}

dependencies {
    compile('org.springframework.boot:spring-boot-starter-web')
    compile('org.projectlombok:lombok')
    testCompile('org.springframework.boot:spring-boot-starter-test')
    testCompile 'junit:junit:4.12'
}

2. intelliJ์™€ Git ์—ฐ๊ฒฐํ•˜๊ธฐ

  • [ctrl + shift + A] โ†’ share project on github

First Commit

  • .ides ๋””๋ ‰ํ† ๋ฆฌ๋Š” ์ปค๋ฐ‹ํ•˜์ง€ ์•Š๋Š”๋‹ค
    • intelliJ ํ”„๋กœ์ ํŠธ ์‹คํ–‰์‹œ ์ž๋™ ์ƒ์„ฑ๋˜๋Š” ํŒŒ์ผ๋“ค์ด๊ธฐ ๋•Œ๋ฌธ
  • ํ”„๋กœ์ ํŠธ ์šฐํด๋ฆญ - git - add : git add
  • [ctrl + k] : git commit
  • [ctrl + shift + k] : git push

.gitignore

  • ๊นƒ์—์„œ ํŠน์ • ํŒŒ์ผ ๋˜๋Š” ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ ๊ด€๋ฆฌ ๋Œ€์ƒ์—์„œ ์ œ์™ธ์‹œ ์‚ฌ์šฉ
  • .gitignore ํ”Œ๋Ÿฌ๊ทธ์ธ์„ ์„ค์น˜
    • ํŒŒ์ผ ์œ„์น˜ ์ž๋™์™„์„ฑ
    • ์ด๊ทธ๋…ธ์–ด ์ฒ˜๋ฆฌ ์—ฌ๋ถ€ ํ™•์ธ ๋“ฑ
profile
https://dsunni.tistory.com/ ์ด์‚ฌ๊ฐ‘๋‹ˆ๋‹ต

0๊ฐœ์˜ ๋Œ“๊ธ€