Spring Framwork VS Spring Boot

์ด๊ฐ•์šฉยท2024๋…„ 1์›” 16์ผ
0

CS

๋ชฉ๋ก ๋ณด๊ธฐ
26/109

๋“ค์–ด๊ฐ€๊ธฐ์— ์•ž์„œ...

๐Ÿง Spring Framework์™€ SpringBoot์˜ ์ฐจ์ด๋ฅผ ์•„์‹œ๋‚˜์š”....?

Spring Framework

  • ์ž๋ฐ”์—์„œ ๊ฐ€์žฅ ๋งŽ์ด ์‚ฌ์šฉ๋˜๋Š” ํ”„๋ ˆ์ž„์›Œํฌ๋กœ ์˜์กด์„ฑ ์ฃผ์ž…(DI, Dependency Injection)๊ณผ ์ œ์–ด์—ญ์ „(IOC, Inversion Of Control), ๊ด€์  ์ง€ํ–ฅ ํ”„๋กœ๊ทธ๋ž˜๋ฐ(AOP, Aspect Oriented Programming)์ด ๊ฐ€์žฅ ์ค‘์š”ํ•œ ์š”์†Œ
  • ์œ„ ์š”์†Œ๋“ค์„ ํ†ตํ•ด ๋Š์Šจํ•œ ๊ฒฐํ•ฉ(Loose Coupling)์„ ๋‹ฌ์„ฑํ•  ์ˆ˜ ์žˆ์Œ
  • ์œ„์™€ ๊ฐ™์ด ๋Š์Šจํ•œ ๊ฒฐํ•ฉ์œผ๋กœ ๊ฐœ๋ฐœํ•œ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋‹จ์œ„ ํ…Œ์ŠคํŠธ๋ฅผ ์ˆ˜ํ–‰ํ•˜๊ธฐ ์šฉ์ดํ•จ

์˜์กด์„ฑ ์ฃผ์ž…(DI, Dependency Injection)

์˜ˆ์ œ ์ฝ”๋“œ
์˜์กด์„ฑ ์ฃผ์ž…์„ ์‚ฌ์šฉํ•˜์ง€ ์•Š์€ ์ฝ”๋“œ

@RestController
public class NoDIController {
	private MyService service = new MyServiceImpl();
    
    @GetMapping("/hello")
    public String getHello(){
    	return service.getHello();
    }
}
  • ์˜ˆ์ œ ์ฝ”๋“œ์™€ ๊ฐ™์ด DI๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š์€ ์ฝ”๋“œ์˜ ๊ฒฝ์šฐ
    • Controller๋Š” MyService ๊ฐ์ฒด์— ์˜์กดํ•˜๊ฒŒ ๋จ
    • ์˜ˆ์ œ ์ฝ”๋“œ์ฒ˜๋Ÿผ ๊ฐ์ฒด์˜ ์ธ์Šคํ„ด์Šค๋ฅผ ์–ป๊ฒŒ ๋˜๋ฉด ๊ฐ์ฒด ๊ฐ„์˜ ๊ฒฐํ•ฉ๋„๊ฐ€ ์˜ฌ๋ผ๊ฐ
    • ์ด๋Ÿฐ ์ฝ”๋“œ ์ž‘์„ฑ์€ ๋‹จ์œ„ํ…Œ์ŠคํŠธ๋ฅผ ์œ„ํ•ด Mock ๊ฐ์ฒด๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์—†๊ฒŒ ๋จ

์˜์กด์„ฑ ์ฃผ์ž…์„ ์‚ฌ์šฉํ•œ ์ฝ”๋“œ


@Service
public class MyServiceImpl implements MyService {
	@Override
	public String getHello(){
    	retunr "Hello";
	}
}

@RestController
public class DIController{
	My Service = myService;
    
    @Autowired
    public DIController(MyService myService){
		this.myService = myService;
	}
    
    @GetMapping("/hello")
    public Sting getHello(){
		retunr mySerVice.getHello();
	}

}

๊ด€์  ์ง€ํ–ฅ ํ”„๋กœ๊ทธ๋ž˜๋ฐ(AOP, Aspect Oriented Programming)

  • ์Šคํ”„๋ง ํ”„๋ ˆ์ž„์›Œํฌ์—์„œ ์ œ๊ณตํ•˜๋Š” ๊ฐ•๋ ฅํ•œ ๊ธฐ๋Šฅ ์ค‘ ํ•˜๋‚˜
  • AOP๋Š” ์‰ฝ๊ฒŒ ๋งํ•ด, OOP๋ฅผ ๋ณด์™„ํ•˜๋Š” ์ˆ˜๋‹จ์œผ๋กœ, ์—ฌ๋Ÿฌ ๊ณณ์— ์“ฐ์ด๋Š” ๊ณตํ†ต ๊ธฐ๋Šฅ์„ ๋ชจ๋“ˆํ™”ํ•˜์—ฌ ํ•„์š”ํ•œ ๊ณณ์— ์—ฐ๊ฒฐํ•จ์œผ๋กœ์จ ์œ ์ง€๋ณด์ˆ˜ ๋˜๋Š” ์žฌ์‚ฌ์šฉ์— ์šฉ์ดํ•˜๋„๋ก ํ•˜๋Š”๊ฒƒ
  • AOP๋ฅผ ํ†ตํ•ด ๊ธฐ์กด ํ”„๋กœ์ ํŠธ์— ๋‹ค์–‘ํ•œ ๊ธฐ๋Šฅ์„ ๋กœ์ง ์ˆ˜์ • ์—†์ด ์ถ”๊ฐ€ํ•  ์ˆ˜ ์žˆ์Œ
  • ์ด๋Ÿฐ ๊ฐœ๋ฐœ ๋ฐฉ์‹์„ ํ†ตํ•ด ๊ฒฐํ•ฉ๋„๋ฅผ ๋‚ฎ์ถ˜ ๊ฐœ๋ฐœ์ด ๊ฐ€๋Šฅํ•จ

SpringBoot

  • Spring ๊ธฐ๋ฐ˜ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๋” ์‰ฝ๊ฒŒ ๋น ๋ฅด๊ฒŒ ๊ฐœ๋ฐœํ•  ์ˆ˜ ์žˆ๋„๋ก ๋•๋Š” ๋„๊ตฌ
  • Spring Boot๋Š” Convention Over Configuration์˜ ์›์น™์— ๋”ฐ๋ผ, ์ตœ์†Œํ•œ์˜ ์„ค์ •์œผ๋กœ Spring ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ์„ค์ •ํ•˜๊ณ  ์‹คํ–‰ํ•ญ ์ˆ˜ ์žˆ๊ฒŒ ํ•จ
  • ๋‚ด์žฅ ์„œ๋ฒ„, ์ž๋™ ์„ค์ •, ์Šคํƒ€ํ„ฐ ์ข…์†์„ฑ ๋“ฑ์„ ์ œ๊ณตํ•˜์—ฌ ๊ฐœ๋ฐœ์ž๊ฐ€ ์ธํ”„๋ผ์— ์‹ ๊ฒฝ ์“ฐ๋Š” ์‹œ๊ฐ„์„ ์ค„์ด๊ณ  ๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง์— ์ง‘์ค‘ํ•  ์ˆ˜ ์žˆ๋„๋ก ๋„์™€์คŒ
    • ์ž๋™์„ค์ •(AutoConfiguration)
      • ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ฐœ๋ฐœ์— ํ•„์š”ํ•œ ๋ชจ๋“  ๋””ํŽœ๋˜์‹œ(Dependency)๋ฅผ ํ”„๋ ˆ์ž„์›Œํฌ์—์„œ ๊ด€๋ฆฌ
      • jarํŒŒ์ผ์ด ํด๋ž˜์Šค ํŒจ์Šค์— ์žˆ๋Š” ๊ฒฝ์šฐ ์Šคํ”„๋ง ๋ถ€ํŠธ๋Š” Dispatcher Servlet์œผ๋กœ ์ž๋™ ๊ตฌ์„ฑ
      • ์Šคํ”„๋ง ๋ถ€ํŠธ๋Š” ๋ฏธ๋ฆฌ ์„ค์ •๋˜์–ด ์žˆ๋Š” Starter ํ”„๋กœ์ ํŠธ๋ฅผ ์ œ๊ณต
      • xml ์„ค์ • ์—†์ด ์ž๋ฐ” ์ฝ”๋“œ๋ฅผ ํ†ตํ•ด ์„ค์ •ํ•  ์ˆ˜ ์žˆ์Œ
      • Spring boot starter denpendency๋ฅผ ํ†ตํ•ด ๋‹ค์–‘ํ•œ ํŒจํ‚ค์ง€๋ฅผ ์ˆ˜์šฉํ•˜๊ณ  ์žˆ์Œ, ์ด๋ฅผ ํ†ตํ•ด ๊ฐœ๋ฐœ์ž๋Š” dependency ๊ด€๋ฆฌ(ํ˜ธํ™˜์„ฑ ์ฒดํฌ ๋“ฑ)์— ๋Œ€ํ•ด ๊ณ ๋ คํ•  ํ•„์š”๊ฐ€ ์—†์Œ

์ •๋ฆฌ

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