Skip to content

04) helloSpringboot

choi jae ho edited this page May 27, 2021 · 30 revisions

๐Ÿ“‹ Spring Boot ๊ด€๋ จ ๊ฐœ๋…

1. Spring Boot ๋ฅผ ์™œ์‚ฌ์šฉํ•˜๋Š”์ง€?

  1. ์ƒ์‚ฐ์„ฑ
  2. Time to Market - ์ ์‹œ์— ์ถœ์‹œํ•˜๋Š”๊ฒŒ ์ค‘์š”ํ•˜๊ธฐ ๋•Œ๋ฌธ.

2. Spring Boot ์˜ ์žฅ์ ?

1) ์ˆ˜๋™์ ์ธ ์„ค์ •์˜ ์–‘์„ ์ตœ์†Œํ™”

auto-configuration - ๊ด€๋ จ๋œ ํด๋ž˜์Šค๊ฐ€ ์žˆ์Œ.
props files & JAR classpath์„ ๊ธฐ๋ฐ˜์œผ๋กœํ•ด์„œ ์ž๋™์œผ๋กœ ์„ค์ •ํ•จ.
xml ํŒŒ์ผ์„ ๋งŒ๋“ค์–ด ์ค„ ํ•„์š”๊ฐ€ ์—†๋‹ค.

2) Dependency conflicts๋ฅผ ํ•ด๊ฒฐ ํ•ด์ค€๋‹ค.

๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๊ฐ„์˜ ๋ฒ„์ „ ์ถฉ๋Œ์ด ๋ฐœ์ƒ ํ•  ์ˆ˜ ์žˆ๋Š”๋ฐ ๊ด€๋ จ๋œ๊ฑธ ์„ธํŒ…

3) embedded server ์ œ๊ณต

์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์•ˆ์— ๋‚ด์žฅ ์„œ๋ฒ„๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ์–ด์„œ ๋ณ„๋„ ์„ค์น˜ ์—†์ด ๋น ๋ฅด๊ฒŒ ์‹œ์ž‘ ํ•  ์ˆ˜ ์žˆ๋‹ค.

3. Spring Boot ์™€ Spring MVC, Spring Rest๋ฅผ ๋Œ€์ฒดํ•˜๋Š” ๊ฒƒ์ธ๊ฐ€?

NO, Spring Boot๊ฐ€ Spring technologies๋ฅผ ํ™œ์šฉ ํ•˜๋Š” ๊ฒƒ์ด๋‹ค.

1

๐Ÿ“‹ Spring Boot 4๊ฐ€์ง€ ํŠน์ง•

1. Auto Configuration

๋™์ผํ•œ ์ž‘์—…์„ ๋ฐ˜๋ณตํ•˜๋Š”๊ฒƒ์„ ์ž๋™ํ™” ํ•œ๋‹ค.
idea : Spring ์ด ์ž๋™์œผ๋กœ bean์„ ์„ค์ •
idea : customize ํ•˜๊ฒŒ ์„ค์ •์ด ํ•„์š”ํ•  ์ˆ˜ ๋„ ์žˆ๊ธฐ ๋•Œ๋ฌธ์—, properties์„ ํ†ตํ•ด cusomizeํ•œ๋‹ค.

EX)

spring mvc jar๊ฐ€ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์— ์ถ”๊ฐ€๋ ๋•Œ, auto configure ํ•˜๋„๋ก ํŒ๋‹จ.
-> spring mvc jar ๊ฐ€ classpath ๊ฐ€ ์žˆ๋‹ค๋ฉด, Dispatcher Servlet์„ ์ž๋™ ์„ค์ •ํ•œ๋‹ค. (์กฐ๊ฑด์— ๋”ฐ๋ผ ์ž๋™ ์„ค์ •ํ•จ)

//@SpringBootApplication : Annotation์˜ ์กฐํ•ฉ 
@Configuration
@EnabledAutoConfiguration // ์ž๋™ ์„ค์ • ๊ธฐ๋Šฅ ํ™œ์„ฑํ™”
@ComponentScan
public class Application {
 ~~ 
} 

@Conditional :์กฐ๊ฑด์„ ์ฒดํฌํ•ด์„œ ์„ค์ •ํ•จ.

image

EX)

image image

2. Easy DependencyManagement

Spring Boot Starter

image

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

Added Dependencies : ์ž๋™์ ์œผ๋กœ Dependencies ์— ์ถ”๊ฐ€

Spring - core, beans, context, aop
Web MVC - (Spring MVC)
Jackson - for JSON Binding
Validation - Hibernate Validator, Validation API
Embedded Servlet Container - Tomcat
Logging - logback, slf4j

3. EmbeddedServer

main() ๋ฉ”์„œ๋“œ๊ฐ€ ์‹œ์ž‘๋˜๋ฉด, ๋‚ด์žฅ์„œ๋ฒ„๋ฅผ ์‹คํ–‰์‹œํ‚จ๋‹ค.
์™ธ๋ถ€์— ํ†ฐ์ผ“ ์„œ๋ฒ„์—์„œ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๋ฐฐํฌํ•  ํ•„์š”๊ฐ€ ์—†๋‹ค.
'war' ํŒŒ์ผ์ด ์•„๋‹Œ 'jar' ๋กœ ํŒจํ‚ค์ง•์ด ์ด๋ฃจ์–ด์ง„๋‹ค.

image

4. SpringBoot Actuator

์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ monitoring , tracing
์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ์„œ๋น„์Šคํ• ๋•Œ ์ค‘์š”ํ•˜๋‹ค.
REST endpoints ๋ฅผ ์ž๋™์ ์œผ๋กœ ์ถ”๊ฐ€ํ•ด์ค€๋‹ค.
EX) /beans, /mappings

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

default : /heath and /info ๊ฐ€ ๋…ธ์ถœ๋˜์–ด ์žˆ์Œ.
Endpoints are prefixed with : /actuator -> /acutator/health

Clone this wiki locally