Notice
Recent Posts
Recent Comments
ยซ   2024/11   ยป
์ผ ์›” ํ™” ์ˆ˜ ๋ชฉ ๊ธˆ ํ† 
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
Archives
Today
In Total
๊ด€๋ฆฌ ๋ฉ”๋‰ด

A Joyful AI Research Journey๐ŸŒณ๐Ÿ˜Š

Spring Boot: ์Šคํ”„๋ง๋ถ€ํŠธ ํ”„๋กœ์ ํŠธ์˜ ๊ตฌ์กฐ ๋ณธ๋ฌธ

๐Ÿ’ปBootcamp Self-Study Revisionโœจ/Spring, Spring Boot, Java, SQL

Spring Boot: ์Šคํ”„๋ง๋ถ€ํŠธ ํ”„๋กœ์ ํŠธ์˜ ๊ตฌ์กฐ

yjyuwisely 2023. 4. 7. 16:31

ํ˜„์žฌ ์Šคํ”„๋ง๋ถ€ํŠธ ์˜ˆ์ œ๋ฅผ ํ†ตํ•ด์„œ ๋กœ๊ทธ์ธ/ํšŒ์›๊ฐ€์ž… ๋งŒ๋“ค๊ณ  ์žˆ๋Š”๋ฐ ๊ตฌ์กฐ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค.

์Šคํ”„๋ง๋ถ€ํŠธ์˜ ํŒŒ์ผ ๊ตฌ์กฐ

src/main/java ๋””๋ ‰ํ„ฐ๋ฆฌ

src/main/java ๋””๋ ‰ํ„ฐ๋ฆฌ์˜ com.mysite.sbb ํŒจํ‚ค์ง€๋Š” ์ž๋ฐ” ํŒŒ์ผ์„ ์ž‘์„ฑํ•˜๋Š” ๊ณต๊ฐ„์ด๋‹ค. ์ž๋ฐ” ํŒŒ์ผ๋กœ๋Š” HelloController์™€ ๊ฐ™์€ ์Šคํ”„๋ง๋ถ€ํŠธ์˜ ์ปจํŠธ๋กค๋Ÿฌ, ํผ๊ณผ DTO, ๋ฐ์ดํ„ฐ ๋ฒ ์ด์Šค ์ฒ˜๋ฆฌ๋ฅผ ์œ„ํ•œ ์—”ํ‹ฐํ‹ฐ, ์„œ๋น„์Šค ํŒŒ์ผ๋“ฑ์ด ์žˆ๋‹ค.

src/main/java/com/mysite/sbb/SbbApplication.java ํŒŒ์ผ

๋ชจ๋“  ํ”„๋กœ๊ทธ๋žจ์—๋Š” ์‹œ์ž‘์„ ๋‹ด๋‹นํ•˜๋Š” ํŒŒ์ผ์ด ์žˆ๋‹ค. ์Šคํ”„๋ง๋ถ€ํŠธ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์—๋„ ์‹œ์ž‘์„ ๋‹ด๋‹นํ•˜๋Š” ํŒŒ์ผ์ด ์žˆ๋Š”๋ฐ ๊ทธ ํŒŒ์ผ์ด ๋ฐ”๋กœ <ํ”„๋กœ์ ํŠธ๋ช…> + Application.java ํŒŒ์ผ์ด๋‹ค. ์Šคํ”„๋ง๋ถ€ํŠธ ํ”„๋กœ์ ํŠธ๋ฅผ ์ƒ์„ฑํ• ๋•Œ "Sbb"๋ผ๋Š” ์ด๋ฆ„์„ ์‚ฌ์šฉํ•˜๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์€ SbbApplication.java ํŒŒ์ผ์ด ์ž๋™์œผ๋กœ ์ƒ์„ฑ๋œ๋‹ค.

[ํŒŒ์ผ๋ช…:/sbb/src/main/java/com/mysite/sbb/SbbApplication.java]

package com.mysite.sbb;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class SbbApplication {

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

SbbApplication ํด๋ž˜์Šค์—๋Š” ์œ„์™€ ๊ฐ™์ด ๋ฐ˜๋“œ์‹œ @SpringBootApplication ์• ๋„ˆํ…Œ์ด์…˜์ด ์ ์šฉ๋˜์–ด ์žˆ์–ด์•ผ ํ•œ๋‹ค. @SpringBootApplication ์• ๋„ˆํ…Œ์ด์…˜์„ ํ†ตํ•ด ์Šคํ”„๋ง๋ถ€ํŠธ์˜ ๋ชจ๋“  ์„ค์ •์ด ๊ด€๋ฆฌ๋œ๋‹ค.

src/main/resources ๋””๋ ‰ํ„ฐ๋ฆฌ

src/main/resources ๋””๋ ‰ํ„ฐ๋ฆฌ๋Š” ์ž๋ฐ” ํŒŒ์ผ์„ ์ œ์™ธํ•œ HTML, CSS, Javascript, ํ™˜๊ฒฝํŒŒ์ผ ๋“ฑ์„ ์ž‘์„ฑํ•˜๋Š” ๊ณต๊ฐ„์ด๋‹ค.

src/main/resources/templates ๋””๋ ‰ํ„ฐ๋ฆฌ

src/main/resources ๋””๋ ‰ํ„ฐ๋ฆฌ์˜ ํ•˜์œ„ ๋””๋ ‰ํ„ฐ๋ฆฌ์ธ templates ๋””๋ ‰ํ„ฐ๋ฆฌ์—๋Š” ํ…œํ”Œ๋ฆฟ ํŒŒ์ผ์„ ์ €์žฅํ•œ๋‹ค. ํ…œํ”Œ๋ฆฟ ํŒŒ์ผ์€ HTML ํŒŒ์ผ ํ˜•ํƒœ๋กœ ์ž๋ฐ” ๊ฐ์ฒด์™€ ์—ฐ๋™๋˜๋Š” ํŒŒ์ผ์ด๋‹ค. templates ๋””๋ ‰ํ„ฐ๋ฆฌ์—๋Š” SBB์˜ ์งˆ๋ฌธ ๋ชฉ๋ก, ์งˆ๋ฌธ ์ƒ์„ธ ๋“ฑ์˜ HTML ํŒŒ์ผ์„ ์ €์žฅํ•œ๋‹ค.

src/main/resources/static ๋””๋ ‰ํ„ฐ๋ฆฌ

static ๋””๋ ‰ํ„ฐ๋ฆฌ๋Š” SBB ํ”„๋กœ์ ํŠธ์˜ ์Šคํƒ€์ผ์‹œํŠธ(.css), ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ(.js) ๊ทธ๋ฆฌ๊ณ  ์ด๋ฏธ์ง€ ํŒŒ์ผ(.jpg, .png) ๋“ฑ์„ ์ €์žฅํ•˜๋Š” ๊ณต๊ฐ„์ด๋‹ค.

application.properties ํŒŒ์ผ from src/main/resources

application.properties ํŒŒ์ผ์€ SBB ํ”„๋กœ์ ํŠธ์˜ ํ™˜๊ฒฝ์„ ์„ค์ •ํ•œ๋‹ค. SBB ํ”„๋กœ์ ํŠธ์˜ ํ™˜๊ฒฝ, ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ๋“ฑ์˜ ์„ค์ •์„ ์ด ํŒŒ์ผ์— ์ €์žฅํ•œ๋‹ค.

src/test/java ๋””๋ ‰ํ„ฐ๋ฆฌ

src/test/java ๋””๋ ‰ํ„ฐ๋ฆฌ๋Š” SBB ํ”„๋กœ์ ํŠธ์—์„œ ์ž‘์„ฑํ•œ ํŒŒ์ผ์„ ํ…Œ์ŠคํŠธํ•˜๊ธฐ ์œ„ํ•œ ํ…Œ์ŠคํŠธ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•˜๋Š” ๊ณต๊ฐ„์ด๋‹ค. JUnit๊ณผ ์Šคํ”„๋ง๋ถ€ํŠธ์˜ ํ…Œ์ŠคํŒ… ๋„๊ตฌ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์„œ๋ฒ„๋ฅผ ์‹คํ–‰ํ•˜์ง€ ์•Š์€ ์ƒํƒœ์—์„œ src/main/java ๋””๋ ‰ํ„ฐ๋ฆฌ์— ์ž‘์„ฑํ•œ ์ฝ”๋“œ๋ฅผ ํ…Œ์ŠคํŠธํ•  ์ˆ˜ ์žˆ๋‹ค.

build.gradle ํŒŒ์ผ

๊ทธ๋ ˆ์ด๋“ค(Gradle)์ด ์‚ฌ์šฉํ•˜๋Š” ํ™˜๊ฒฝ ํŒŒ์ผ์ด๋‹ค. ๊ทธ๋ ˆ์ด๋“ค์€ ๊ทธ๋ฃจ๋น„(Groovy)๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ํ•œ ๋นŒ๋“œ ๋„๊ตฌ๋กœ Ant, Maven๊ณผ ๊ฐ™์€ ์ด์ „ ์„ธ๋Œ€ ๋นŒ๋“œ ๋„๊ตฌ์˜ ๋‹จ์ ์„ ๋ณด์™„ํ•˜๊ณ  ์žฅ์ ์„ ์ทจํ•ฉํ•˜์—ฌ ๋งŒ๋“  ๋นŒ๋“œ ๋„๊ตฌ์ด๋‹ค. build.gradle ํŒŒ์ผ์—๋Š” ํ”„๋กœ์ ํŠธ๋ฅผ ์œ„ํ•ด ํ•„์š”ํ•œ ํ”Œ๋Ÿฌ๊ทธ์ธ๊ณผ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ๋“ฑ์„ ๊ธฐ์ˆ ํ•œ๋‹ค.

์ฐธ๊ณ : https://wikidocs.net/160947


728x90
๋ฐ˜์‘ํ˜•
Comments