๐Ÿ–ฅ๏ธ Web Development Study/Back-End

[Back-End] ์Šคํ”„๋ง ์ž…๋ฌธ :: ํ™˜๊ฒฝ ์…‹ํŒ…(Java, IntelliJ, Spring Boot Starter)

ibelieveinme 2024. 4. 10. 21:39
728x90

#1๊ฐ•_ํ™˜๊ฒฝ์„ค์ •

 

1) Java Install

https://www.oracle.com/java/technologies/downloads/#jdk22-windows

 

Download the Latest Java LTS Free

Subscribe to Java SE and get the most comprehensive Java support available, with 24/7 global access to the experts.

www.oracle.com

 

2) IntelliJ Install

https://www.jetbrains.com/help/idea/installation-guide.html#toolbox

 

Install IntelliJ IDEA | IntelliJ IDEA

 

www.jetbrains.com

=> Ultimate ๋ฒ„์ „์€ ์œ ๋ฃŒ๋„ค...? ํ•™์ƒ ์ธ์ฆํ•˜๋ฉด ๋ฌด๋ฃŒ๋ผ๊ณ  ํ•˜๋‹ˆ ๋™์ƒ๋“ค์„ ํฌ์„ญํ•ด๋ณด์„ธ...ใ…Ž_ใ…Ž

 

3) Spring Boot Starter ์—์„œ Spring Project ์ƒ์„ฑ

https://start.spring.io/

Artifact ๊ฐ€ ํ”„๋กœ์ ํŠธ ์ด๋ฆ„์ด๋‹ค. ์›ํ•˜๋Š” ํ”„๋กœ์ ํŠธ ์ด๋ฆ„์„ ์ ์–ด์ฃผ๋ฉด Name, PackageName์— ์ž๋™์œผ๋กœ ๋ฐ˜์˜๋œ๋‹ค.

PackageName ์€ ๋‹ค๋ฅธ ๋„๊ตฌ๋“ค๊ณผ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ 'Group๋ช….ํ”„๋กœ์ ํŠธ์ด๋ฆ„' ์œผ๋กœ ์กฐํ•ฉ๋˜์–ด ๋งŒ๋“ค์–ด์ง„๋‹ค.

 

*Gradle๊ณผ Maven์˜ ์ฐจ์ด?

๋‘˜๋‹ค Build ๊ด€๋ฆฌ ๋„๊ตฌ์ด๋‹ค.

 

- Maven: Java ์ „์šฉ ํ”„๋กœ์ ํŠธ ๊ด€๋ฆฌ ๋„๊ตฌ.  Apache Ant ์˜ ๋Œ€์•ˆ์œผ๋กœ ๋งŒ๋“ค์–ด์ง. Apache Ant์™€ ๋‹ฌ๋ฆฌ Lifecycle ๊ด€๋ฆฌ ๋„๊ตฌ๋กœ ์ •ํ•ด์ง€ Lifecycle ์— ์˜ํ•ด ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•œ๋‹ค. XML๋กœ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์ •์˜ํ•˜๊ณ  ํ™œ์šฉ.

- Gradle: Java, C/C++, Python ๋“ฑ์„ ์ง€์›ํ•œ๋‹ค. ๋ณ„๋„์˜ Groovy ๋นŒ๋“œ ์Šคํฌ๋ฆฝํŠธ๋กœ ์‚ฌ์šฉํ•  ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋ฒ„์ „, ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋“ฑ์˜ ํ•ญ๋ชฉ์„ ์„ค์ •.

 

Gradle ์€ Groovy ์Šคํฌ๋ฆฝํŠธ ์–ธ์–ด(Java ๋ฌธ๋ฒ•๊ณผ ์œ ์‚ฌ)๋กœ ๊ตฌ์„ฑ๋˜์–ด ์žˆ๊ธฐ ๋•Œ๋ฌธ์— XML๊ณผ ๋‹ฌ๋ฆฌ ๋ณ€์ˆ˜์„ ์–ธ, if, else, for๋“ฑ์˜ ๋กœ์ง์ด ๊ตฌํ˜„๊ฐ€๋Šฅํ•˜์—ฌ ๋” ๊ฐ„๊ฒฐํ•˜๊ฒŒ ๊ตฌ์„ฑ ๊ฐ€๋Šฅํ•˜๋‹ค. Maven ๋ณด๋‹ค ๋น ๋ฅด๋‹ค.

Dependencies ๋กœ Spring Boot Project ์— ๋„๊ตฌ๋ฅผ ์ถ”๊ฐ€ํ•  ์ˆ˜ ์žˆ๋‹ค.

Spring Web, Thymeleaf ๋ฅผ ์ถ”๊ฐ€ํ•ด ์ฃผ์ž.

 

- Spring Web: web ๋นŒ๋“œ ๋„๊ตฌ

- Thymeleaf: HTML ์„ ๋งŒ๋“ค์–ด์ฃผ๋Š” ํ…œํ”Œ๋ฆฟ ์—”์ง„

- H2 Database: ์ž๋ฃŒ๋ฅผ ์ €์žฅํ•˜๊ธฐ ์œ„ํ•œ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค

- Mustache: ํ™”๋ฉด์„ ๋งŒ๋“ค๊ธฐ ์œ„ํ•ด ํ•„์š”ํ•œ ๋„๊ตฌ

- Spring Data JPA: ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋ฅผ ์ข€ ๋” ํŽธ๋ฆฌํ•˜๊ฒŒ ๋‹ค๋ฃฐ ์ˆ˜ ์žˆ๊ฒŒ ํ•ด์ฃผ๋Š” ๋„๊ตฌ

 

4) ํ”„๋กœ์ ํŠธ ๋‚ด๋ ค๋ฐ›๊ธฐ

Generate ํ•ด์„œ ํ”„๋กœ์ ํŠธ๋ฅผ ๋‚ด๋ ค๋ฐ›๋Š”๋‹ค. 

์••์ถ•ํŒŒ์ผ ์—ด์–ด๋ณด๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์€ ํด๋” ๋ฐ ํŒŒ์ผ๋กœ ๊ตฌ์„ฑ๋˜์–ด ์žˆ๋‹ค.

 

5. IntelliJ ๋กœ ์œ„ ํŒŒ์ผ ์—ด๊ธฐ

IntelliJ ๋กœ ์œ„์—์„œ ๋งŒ๋“  Spring Boot Project ๋ฅผ ์—ด์–ด์ค€๋‹ค. ๊ทธ๋Ÿผ ์ž๋™์œผ๋กœ IntelliJ ๊ฐ€ ํ™˜๊ฒฝ์„ ์…‹ํŒ…ํ•ด์ค€๋‹ค.

 

์ด๋•Œ, Spring Version ์ด๋ž‘ JDK ๋ฒ„์ „์ด ์•ˆ๋งž์œผ๋ฉด ์—๋Ÿฌ๊ฐ€ ๋‚œ๋‹ค.

๋‚˜๋„ ๊ธฐ์กด์— ์„ค์น˜ํ•ด๋‘” JDK ๋ฒ„์ „์ด๋ž‘ ์—๋Ÿฌ๊ฐ€ ๋‚ฌ๋Š”๋ฐ JDK 21(LTS๋ฒ„์ „), Spring Boot 3.3.0 ์œผ๋กœ ๋งž์ถฐ์ฃผ๋‹ˆ ๋๋‹ค.

 

.idea: IntelliJ ๊ฐ€ ์‚ฌ์šฉํ•˜๋Š” ์„ค์ • ํŒŒ์ผ

gradle: Gradle ๊ด€๋ จ ํŒŒ์ผ๋“ค

src: java, test ์ฝ”๋“œ. Test ์ฝ”๋“œ๊ฐ€ Default ๋กœ ์žˆ๋Š” ๊ฑธ๋กœ ์•Œ ์ˆ˜ ์žˆ๋“œ์‹œ ๊ฐœ๋ฐœ ํŠธ๋ Œ๋“œ์— ์žˆ์–ด์„œ Test ์ฝ”๋“œ๊ฐ€ ์ค‘์š”ํ•˜๋‹ค.

 

build.gradle: ๋ฒ„์ „ ์„ค์ • ๋‚ด์šฉ, ์ถ”๊ฐ€๋œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ๊ด€๋ฆฌ ํŒŒ์ผ.

mavenCentral() ์ด๋ผ๋Š” ๊ณต๊ฐœ๋œ ์‚ฌ์ดํŠธ์—์„œ dependencies ๋“ค์ด ๋‹ค์šด๋ฐ›์•„์ง€๋Š” ๊ฒƒ.

๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์ถ”๊ฐ€ํ•˜๋ฉด ์˜์กด๊ด€๊ณ„๊ฐ€ ์žˆ๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋“ค์„ ์‹น ๋‹ค ๊ฐ™์ด ๊ฐ€์ ธ์™€์ง„๋‹ค.

thymleaf ๋ฅผ ์ถ”๊ฐ€ํ–ˆ๋Š”๋ฐ spring-boot-starter > spring-boot > spring-core ๊นŒ์ง€ ๋‹ค ๋ฐ›์•„์™€์ง„๊ฑธ ๋ณผ ์ˆ˜ ์žˆ๋‹ค.

 

5) Spring Boot main ํ•จ์ˆ˜ ์‹คํ–‰ํ•˜๊ธฐ

Project ๋ฅผ ์‹คํ–‰ํ•ด๋ณด์ž. Java ๋Š” main ํ•จ์ˆ˜๋ฅผ ๊ธฐ์ ์œผ๋กœ ์‹œ์ž‘๋œ๋‹ค.

Tomcat started on port 8080 (http) with context path '/' ๋ผ๋Š” ๋ฌธ๊ตฌ๊ฐ€ ๋œจ๋Š”๋ฐ ์ด๋Š”  tomcat ์ด๋ผ๋Š” ๋‚ด์žฅ ์„œ๋ฒ„๋ฅผ ๋„์šฐ๊ณ , tomcat ์ด 8080 port ๋ฅผ ์‹คํ–‰ํ–ˆ๋‹ค๋Š” ๋œป์ด๋‹ค.

http://localhost:8080/

์œผ๋กœ ์ ‘์†ํ•ด๋ณด๋ฉด ์œ„์™€ ๊ฐ™์€ ํŽ˜์ด์ง€๊ฐ€ ๋œจ๋Š” ๊ฑธ ๋ณผ ์ˆ˜ ์žˆ๋‹ค. ๊ทธ๋Ÿผ ์„ฑ๊ณต์ด๋‹ค.

 

Project ์‹คํ–‰์ด ๋˜๊ฒŒ ๋Š๋ฆฐ๋ฐ ์„ค์ •์—์„œ ๋นŒ๋“œ๋ฅผ Gradle ์ด ์•„๋‹Œ IntelliJ IDEA ๋กœ ๋ณ€๊ฒฝํ•ด์ฃผ๋ฉด Gradle ์„ ํ†ตํ•˜์ง€ ์•Š๊ณ  IntelliJ ์—์„œ Java๋ฅผ ๋ฐ”๋กœ ๋„์›Œ์„œ ๋น ๋ฅด๋‹ค. ์—ฐ์Šต๋• IntelliJ ๋กœ ์…‹ํŒ…ํ•ด์ฃผ๊ธฐ.

728x90