Intro.Spring Framework

๐Ÿ“Œ Spring : Java ๊ธฐ๋ฐ˜ ์˜คํ”ˆ์†Œ์Šค Back-end ํ”„๋ ˆ์ž„์›Œํฌ

  • "๊ฐœ๋ฐœ์ž์—๊ฒŒ ๊ฒจ์šธ์€ ๋๋‚˜๊ณ  ๋ด„์ด ์™”๋‹ค"

  • ๋™์ ์ธ ์›น์‚ฌ์ดํŠธ ๊ฐœ๋ฐœ์„ ์œ„ํ•œ ์—ฌ๋Ÿฌ๊ฐ€์ง€ ์„œ๋น„์Šค๋ฅผ ์ œ๊ณตํ•จ

  • ๋Œ€ํ•œ๋ฏผ๊ตญ ๊ณต๊ณต๊ธฐ๊ด€ ์›น์„œ๋น„์Šค ๊ฐœ๋ฐœ ์‹œ ์‚ฌ์šฉ์„ ๊ถŒ์žฅํ•˜๋Š” ์ „์ž์ •๋ถ€ ํ‘œ์ค€ํ”„๋ ˆ์ž„์›Œํฌ์˜ ๊ธฐ๋ฐ˜๊ธฐ์ˆ 


1 Spring Framework ํŠน์ง•

1๏ธโƒฃ DI

๐Ÿ“Œ DI(Dependency Injection) : ๊ฐœ๋ฐœ์ž๊ฐ€ Spring ํ”„๋ ˆ์ž„์›Œํฌ์— ์˜์กด์„ฑ์ฃผ์ž… โ†’ ๊ฐ์ฒด ๊ฐ„ ๋Š์Šจํ•œ ๊ฒฐํ•ฉ์„ ๋งŒ๋“ฆ

  • ์™ธ๋ถ€์—์„œ ๋‘ ๊ฐ์ฒด ๊ฐ„์˜ ๊ด€๊ณ„๋ฅผ ๊ฒฐ์ •ํ•ด์ฃผ๋Š” ๋””์ž์ธ ํŒจํ„ด

  • ๋‘ ํด๋ž˜์Šค ์‚ฌ์ด์— interface โ†’ ํด๋ž˜์Šค๋ผ๋ฆฌ๋Š” ์˜์กด๊ด€๊ณ„ ๊ณ ์ • โ›”๏ธ, ๋Ÿฐํƒ€์ž„ ์‹œ ๊ด€๊ณ„๋ฅผ ๋™์ ์œผ๋กœ ์ฃผ์ž… โœ…

    • ์ฝ”๋“œ์˜ ์žฌ์‚ฌ์šฉ์„ฑ ์ฆ๊ฐ€

    • ๋‹จ์œ„ํ…Œ์ŠคํŠธ ์šฉ์ด

2๏ธโƒฃ IoC

๐Ÿ“Œ IoC(Inversion of Control) : ๊ฐ์ฒด์˜ ์ปจํŠธ๋กค ์ œ์–ด๊ถŒ โ†’ ๊ฐœ๋ฐœ์ž โŒ, Spring Framework โœ…

Java ํ”„๋กœ๊ทธ๋ž˜๋ฐ์—์„œ๋Š” class ์ƒ์„ฑ ํ›„, new ์ƒ์„ฑ์ž โ†’ ๊ฐ์ฒด๋ฅผ ์ง์ ‘ ์ƒ์„ฑ ํ›„ ์‚ฌ์šฉํ•จ
Spring์—์„œ๋Š” new ์ƒ์„ฑ์ž๋ฅผ ์ด์šฉํ•ด ์ƒ์„ฑํ•œ ๊ฐ์ฒด โ›”๏ธ,
Spring์— ์˜ํ•˜์—ฌ ๊ด€๋ฆฌ๋‹นํ•˜๋Š” Java ๊ฐ์ฒด๋ฅผ ์‚ฌ์šฉํ•จ โญ๏ธ

๐Ÿ’ก Java ํ”„๋กœ๊ทธ๋žจ

  • ๊ฐ ๊ฐ์ฒด๋“ค์ด ํ”„๋กœ๊ทธ๋žจ์˜ ํ๋ฆ„์„ ๊ฒฐ์ •ํ•จ

  • ๊ฐ ๊ฐ์ฒด๋ฅผ ๊ฐœ๋ฐœ์ž๊ฐ€ ์ง์ ‘ ์ƒ์„ฑ ๋ฐ ์กฐ์ž‘ํ•จ (๊ฐ์ฒด์ƒ์„ฑ โ†’ method ํ˜ธ์ถœ)

  • "๋ชจ๋“  ์ž‘์—…์„ ๊ฐœ๋ฐœ์ž๊ฐ€ ์ œ์–ดํ•˜๋Š” ๊ตฌ์กฐ"

๐Ÿ’ก IoC ์ œ์–ด์˜์—ญ์ „

  • ๊ฐ์ฒด์˜ ์ƒ์„ฑ ๋ฐ ๊ด€๋ฆฌ โ†’ ์œ„์ž„ ์ฃผ์ฒด์— ๋งก๊น€

  • ๊ฐœ๋ฐœ์ž๊ฐ€ ์ง์ ‘ ๊ฐ์ฒด์ƒ์„ฑ ๋ฐ ์˜์กด๊ด€๊ณ„ ์„ค์ • โ›”๏ธ

  • Servlet, Bean โ†’ Spring Framework๊ฐ€ ๋Œ€์‹ ์ˆ˜ํ–‰

๐Ÿ“ Bean
	- Spring IoC ์ปจํ…Œ์ด๋„ˆ๊ฐ€ ๊ด€๋ฆฌํ•˜๋Š” Java ๊ฐ์ฒด
    - Spring์— ์˜ํ•ด ์ƒ์„ฑ๋˜๊ณ  ๊ด€๋ฆฌ๋˜๋Š” Java ๊ฐ์ฒด

๐Ÿ“ Servlet
	- Java๋ฅผ ์‚ฌ์šฉํ•ด ์›น์„œ๋น„์Šค๋ฅผ ๋งŒ๋“ค ๋•Œ ํ•„์š”ํ•จ
    - Client Request์— ๋Œ€ํ•ด Response๋ฅผ ๋‹ค์‹œ ์ „์†กํ•ด์ฃผ๋Š” ์—ญํ• 
    - ์›น์„œ๋ฒ„๊ฐ€ ๋™์ ์ธ ํŽ˜์ด์ง€๋ฅผ ์ œ๊ณตํ•  ์ˆ˜ ์žˆ๋„๋ก ๋„์™€์ฃผ๋Š” ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜

3๏ธโƒฃ AOP

๐Ÿ“Œ AOP : ํ•ต์‹ฌ๊ธฐ๋Šฅ์„ ์ œ์™ธํ•œ ๋ถ€์ˆ˜์ ์ธ ๊ธฐ๋Šฅ โ†’ Framework๊ฐ€ ์ œ๊ณตํ•˜๋Š” ํŠน์ง•

  • Spring project โ†’ security ์ ์šฉ

  • Spring project โ†’ logging ์ ์šฉ

  • ๊ธฐ์กด ๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง ๋ณ€๊ฒฝ โ›”๏ธ, AOP๋กœ ์ถ”๊ฐ€๊ฐ€๋Šฅ โœ…

4๏ธโƒฃ ์ค‘๋ณต์ฝ”๋“œ์ œ๊ฑฐ

  • Spring Framework โ†’ ์ค‘๋ณต๋˜๋Š” ์ฝ”๋“œ๋ฅผ ๋ชจ๋‘ ์ œ๊ฑฐํ•จ

  • ์ฝ”๋“œ๊ฐ€ ๋‹จ์ˆœํ•˜๊ณ  ์‰ฌ์›Œ์ง

5๏ธโƒฃ ์œ ์—ฐ์„ฑ

  • JUnit, Mockito ๋“ฑ ์œ ๋‹›ํ…Œ์ŠคํŠธ Framework์™€ ํ†ตํ•ฉ๊ฐ€๋Šฅ

  • ๊ฐœ๋ฐœ ํ”„๋กœ๊ทธ๋žจ์˜ ํ’ˆ์งˆ์ด ํ–ฅ์ƒ๋จ


2 Spring๊ณผ SpringBoot ์ฐจ์ด์ 

1๏ธโƒฃ Dependency

๐Ÿ’ก Spring Framework

  • dependency ์„ค์ • โ†’ ์„ค์ •ํŒŒ์ผ์ด ๋งค์šฐ ๊ธธ๊ณ  ๋ณต์žกํ•จ

  • dependency ๋ฒ„์ „๊ด€๋ฆฌ โ†’ ๊ฐœ๋ฐœ์ž๊ฐ€ ํ•˜๋‚˜ํ•˜๋‚˜ ํ•ด์ค˜์•ผํ•จ

๐Ÿ’ก SpringBoot Framework

  • dependency ์„ค์ • โ†’ ํ•œ์ค„๋กœ ๊ฐ€๋Šฅ

  • ๋ฒ„์ „๊ด€๋ฆฌ ์ž๋™์œผ๋กœ ํ•ด์คŒ

implementation 'org.springframework.boot:spring-boot-starter-web'

๐Ÿ“ BuildGradle โ†’ dependency ์ถ”๊ฐ€
๐Ÿ“ ์›น๊ฐœ๋ฐœ ํ•„์š” dependency ๋ชจ๋‘ ์ž๋™์œผ๋กœ ์ถ”๊ฐ€ํ•˜๊ณ  ๊ด€๋ฆฌํ•ด์คŒ

2๏ธโƒฃ Configuration

๐Ÿ’ก Spring Framework

  • configuration ์„ค์ • ๋งค์šฐ ๋ณต์žก

  • ๋ชจ๋“  ์–ด๋…ธํ…Œ์ด์…˜ ๋ฐ Bean ๋“ฑ๋ก ์„ค์ • ํ•ด์ค˜์•ผํ•จ

๐Ÿ’ก SpringBoot Framework

  • application.properties or application.yml โ†’ configuration ์„ค์ •
๐Ÿ“ SpringBoot AutoConfiguration
	- ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ฐœ๋ฐœ โ†’ class์— @SpringBootApplication ์–ด๋…ธํ…Œ์ด์…˜
    - ์™ธ๋ถ€ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ, ๋‚ด์žฅ ํ†ฐ์บฃ์„œ๋ฒ„ ๋“ฑ ์‹คํ–‰๋จ
    - @Component + @Controller + @Service + @Repository
      โžก๏ธ ์ž๋™์œผ๋กœ Bean ๋“ฑ๋กํ•จ

3๏ธโƒฃ ๋ฐฐํฌ ํŽธ๋ฆฌ์„ฑ

๐Ÿ’ก Spring Framework

  • war ํŒŒ์ผ โ†’ WAS ์ •ํ•จ โ†’ Web application server์— ๋‹ด์•„ ๋ฐฐํฌ

๐Ÿ’ก SpringBoot Framework

  • Tomcat, Jetty ๋“ฑ ๋‚ด์žฅ WAS๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ์Œ

  • jar ํŒŒ์ผ๋กœ ๊ฐ„๋‹จํ•˜๊ฒŒ ๋ฐฐํฌ๊ฐ€๋Šฅ


Outro

SpringBoot Framework๋Š” Spring Framework๋ณด๋‹ค ๊ฐœ๋ฐœ์ž๊ฐ€ ๋”์šฑ ๊ฐœ๋ฐœ์—๋งŒ ์ง‘์ค‘ํ•  ์ˆ˜ ์žˆ๋„๋ก ๋„์™€์ฃผ๋Š” Framework

profile
๐ŸฑSunyeon-Jeong, mallang developer๐Ÿฐ

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

comment-user-thumbnail
2023๋…„ 7์›” 17์ผ

๋„ˆ๋ฌด ์ข‹์€ ๊ธ€์ด๋„ค์š”. ๊ณต์œ ํ•ด์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค.

๋‹ต๊ธ€ ๋‹ฌ๊ธฐ