์คํ๋ง๊ณผ ์คํ๋ง ๋ถํธ๋ versus๊ฐ ์๋๋ผ with์ด๋ค.
1. Spring
์คํ๋ง ํ๋ ์์ํฌ๋ ์๋ฐ์์ ๊ฐ์ฅ ๋์ค์ ์ธ ์์ฉํ๋ก๊ทธ๋จ ๊ฐ๋ฐ ํ๋ ์์ํฌ์ด๋ค.
1) ํน์ง
๊ฐ์ฅ ์ค์ํ ํน์ง์ ์์กด์ฑ ์ฃผ์ (Dependency Injection)๊ณผ ์ ์ด์ ์ญ์ (Inversion Of Control)์ด๋ค. ์ด๋ฌํ ๊ฐ๋ฐ ๋ฐฉ์์ ์ฌ์ฉํ๋ค๋ฉด ๊ฒฐํฉ๋๋ฅผ ๋ฎ์ถ ์ ์๊ณ ๋จ์ ํ ์คํธ๋ฅผ ์ฉ์ดํ๊ฒ ํ์ฌ ํ๋ฆฌํฐ ๋์ ํ๋ก๊ทธ๋จ์ ๊ฐ๋ฐํ ์ ์๋ค.
// 1. DI ์๋ ์์ : ๊ฐ์ฒด ๊ฐ์ ๊ฒฐํฉ๋๊ฐ ๋๋ค.
// MyController๋ MyService ํด๋์ค์ ์์กดํ๋ค.
// ๊ทธ๋์ ์ธ์คํด์ค๋ฅผ ์ป๊ธฐ ์ํด์ new MyService();๋ก ๊ฐ์ฒด์ ์ธ์คํด์ค๋ฅผ ์ป์ด์ผ ํ๋ค.
// ๊ทธ๋ฐ๋ฐ MyController์ ๋ํ ๋จ์ ํ
์คํธ๋ฅผ ์ํด Mock ๊ฐ์ฒด๋ฅผ ์์ฑํ์ ๋,
// ์ด๋ป๊ฒ MyController๊ฐ Mock ๊ฐ์ฒด๋ฅผ ์ฌ์ฉํ ์ ์์๊น? ๋ฐฉ๋ฒ์ด ์์ ๊ฒ์ด๋ค.
@RestController
public class MyController {
private MyService service = new MyService();
@RequestMapping("/welcome")
public String welcome() {
return service.retrieveWelcomeMessage();
}
}
// 2. DI ์๋ ์์ : ๊ฐ์ฒด ๊ฐ์ ๊ฒฐํฉ๋๊ฐ ๋ฎ๋ค.
// ๋ ๊ฐ์ ์ด๋
ธํ
์ด์
์ผ๋ก MyService ๊ฐ์ฒด์ ์ธ์คํด์ค๋ฅผ ์ฝ๊ฒ ์ป์ ์ ์๋ค.
// 1) @Component : ์คํ๋ง ํฉํ ๋ฆฌ ํจํด(BeanFactory)์ ๊ตฌํ์ฒด์์ ์คํ๋ง์ด ๊ด๋ฆฌํ๋ ๊ฐ์ฒด(bean)๊ฐ ์๋๋ฐ,
// ํด๋น ํด๋์ค๋ฅผ ๊ทธ๋ฌํ bean ๊ฐ์ฒด๋ก ๋์ด ์คํ๋ง ๊ด๋ฆฌํ์ ๋๊ฒ ๋ค๋ ์ด๋
ธํ
์ด์
์ด๋ค.
// 2) @Autowired : Bean ๊ฐ์ฒด์ ๊ฐ์ ํ์
์ ๊ฐ์ฒด๋ฅผ ์ฐพ์์ ์๋์ผ๋ก ์ฃผ์
ํด ์ฃผ๋ ๊ฒ์ผ๋ก,
// ํด๋น ๊ฐ์ฒด๋ฅผ Bean์ผ๋ก ๋ฑ๋กํ์ง ์์ผ๋ฉด ์ฃผ์
ํด ์ค ์ ์๋ค.
// MyService์ ๋ํ bean์ ์์ฑํ๊ณ MyController์ ์๋ service ๋ณ์์ ์ฃผ์
ํ์ฌ ์ธ์คํด์ค๋ฅผ ๋ง๋ค์๋ค.
@Component
public class MyService {
public String retrieveWelcomeMessage(){
return "Welcome to InnovationM";
}
}
@RestController
public class MyController {
@Autowired
private MyService service;
@RequestMapping("/welcome")
public String welcome() {
return service.retrieveWelcomeMessage();
}
}
2) ๊ธฐ๋ฅ
์คํ๋ง ํ๋ ์์ํฌ์ ๋ค๋ฅธ ๋ง์ ๊ธฐ๋ฅ๋ค์ด ์๋ค. ๊ทธ ๊ธฐ๋ฅ๋ค์ ์ฝ ์ค๋ฌด ๊ฐ์ ๋ชจ๋๋ก ๋๋์ด ์์ผ๋ฉฐ ํํ ๋ฐ์ํ๋ ๋ฌธ์ ๋ค์ ํด๊ฒฐํ ์ ์๋ค.
- Spring JDBC
- Spring MVC
- Spring AOP
- Spring ORM
- Spring JMS
- Spring Test
- Spring Expression Language (SpEL)
์ฌ๊ธฐ์ ๊ด์ ์งํฅ ํ๋ก๊ทธ๋๋ฐ(AOP, Aspect Oriented Programming)์ ์คํ๋ง์์ ์์ฃผ ๊ฐ๋ ฅํ ๊ธฐ๋ฅ์ด๋ค. ๊ฐ์ฒด ์งํฅ ํ๋ก๊ทธ๋๋ฐ์์ ํต์ฌ ํฌ์ธํธ๋ Class์ด์ง๋ง AOP์์๋ ๊ด์ (Aspect)์ด๋ค. ์๋ฅผ ๋ค์ด, ๊ธฐ์กด ํ๋ก์ ํธ์ security๋ logging ๋ฑ์ ์ถ๊ฐํ๊ณ ์ถ์ ๋ ๊ธฐ์กด ๋น์ฆ๋์ค ๋ก์ง์๋ ์์ ๋์ง ์๊ณ AOP๋ฅผ ํ์ฉํ์ฌ ์ถ๊ฐํ ์ ์๋ค. ํน์ ๋ฉ์๋๊ฐ ๋๋ ๋ ํธ์ถํ ์๋ ์๊ณ , ํธ์ถ ์ง์ , ๋ฉ์๋๊ฐ ๋ฆฌํดํ ์งํ ํน์ ์์ธ๊ฐ ๋ฐ์ํ์ ๋ ๋ฑ ์ฌ๋ฌ ๊ฐ์ง ์ํฉ์ ํ์ฉํ ์ ์๋ค.
์คํ๋ง ํ๋ ์์ํฌ๋ ์น ์ ํ๋ฆฌ์ผ์ด์ ์ ๊ฐ๋ฐํ๋๋ฐ ๊ฒฐํฉ๋๋ฅผ ๋ฎ์ถ๋ ๋ฐฉํฅ์ ๊ฐ๋ฐ ๋ฐฉ๋ฒ์ ์ ๊ณตํ๋ค.
๊ทธ๋์ ์น ์ ํ๋ฆฌ์ผ์ด์ ์ ๊ฐ๋ฐ์ ์คํ๋ง ๋๋ถ์ ์ฌ์ด ๊ฐ๋ฐ์ด ๊ฐ๋ฅํ๋ค.
3) ์์ฒญ-์๋ต ๊ณผ์
https://data-make.tistory.com/714
[HTTP Spring ํต์ ํ๋ฆ ๊ณผ์ ] HTTP Request ๋ถํฐ HTTP Response ๊น์ง์ ์ฌ์
HTTP Request ๋ถํฐ HTTP Response ๊น์ง์ ์ฌ์ ์์ฆ ์ฌํ ๊ฐ๋ ๊ฒ๋ ํ๋ ๋ฐ.. HTTP ํ๊ณ ์ฌํ์ด๋ ๊ฐ๋ณด์! ๋จผ์ HTTP ๋ ์ธํฐ๋ท์์ ๋ฐ์ดํฐ๋ฅผ ์ฃผ๊ณ ๋ฐ์ ์ ์๋ ํ๋กํ ์ฝ ์ ์๋ฏธํ๋ค. ์น ๋ธ๋ผ์ฐ์ ์ URL ์
data-make.tistory.com
https://gyoogle.dev/blog/web-knowledge/spring-knowledge/Spring%20MVC.html
Spring MVC Framework | ๐จ๐ป๐ป Tech Interview
Spring MVC Framework ํด๋ผ์ด์ธํธ๊ฐ ์๋ฒ์๊ฒ url์ ํตํด ์์ฒญํ ๋ ์ผ์ด๋๋ ์คํ๋ง ํ๋ ์์ํฌ์ ๋์์ ๊ทธ๋ฆผ์ผ๋ก ํํํ ๊ฒ์ด๋ค. MVC ์งํ ๊ณผ์ ํด๋ผ์ด์ธํธ๊ฐ url์ ์์ฒญํ๋ฉด, ์น ๋ธ๋ผ์ฐ์ ์์ ์คํ
gyoogle.dev
2. SpringBoot
์คํ๋ง์ด ์ดํ ๋ก ๋ง์ ๋ฌธ์ ๋ค์ ํด๊ฒฐํ ๊ธฐ๋ฅ์ ์ด๋ฏธ ์ ๊ณตํ๊ณ ์๋๋ฐ ์ ์คํ๋ง ๋ถํธ๊ฐ ํ์ํด์ก์๊น?
๊ฐ๋ฐ์๋ค์ด ์คํ๋ง์ ์ด์ฉํด ์ ํ๋ฆฌ์ผ์ด์ ์ ๊ฐ๋ฐํ๋ฉด์ ์ง๋ฉดํ ๋ฌธ์ ๋ค์ด ์์ ๊ฒ์ด๋ค.
์ต์ํ์ ๊ธฐ๋ฅ์ผ๋ก Spring MVC๋ฅผ ์ฌ์ฉํ์ฌ ๊ธฐ๋ณธ ํ๋ก์ ํธ๋ฅผ ์ธํ ํ๋๋ฐ ๊ฐ๋ฐ์์๊ฒ ๋๋ฌด ๋ง์ ์๊ฐ์ด ํ์ํ๋ค.
"์คํ๋ง์ ์ค์ ์ด ๋ฐ์ด๋ค"๋ผ๋ ๋ง์ด ์์ ์ ๋์ด๋ค.
(Transaction Manager, Hibernate Datasource, Entity Manager, Session Factory์ ๊ฐ์ ์ค์ )
๊ทธ๋์ ์คํ๋ง์ ๋จ์ ์ ํด๊ฒฐํ๊ณ ์ ์คํ๋ง ๋ถํธ๋ฅผ ์ฌ์ฉํ๋ค. ํ๊ฒฝ ์ค์ ์ ์ต์ํํด์ฃผ์ด ๊ฐ๋ฐ์๊ฐ ๋น์ฆ๋์ค ๋ก์ง์ ์ง์คํ ์ ์๋๋ก ๋์์ค๋ค.
1) Spring Boot Starter
๊ธฐ์กด์๋ ์คํ๋ง์ ์ฌ์ฉํ ๋ ๋ฒ์ ๊น์ง ๋ช ์ํ๊ณ ๋ฒ์ ์ ๋ง๋ ์ค์ ์ ํ์์ง๋ง, dependency ๊ด๋ฆฌ๋ฅผ ์คํ๋ง ๋ถํธ์ ์ํด์ ๊ด๋ฆฌ๋๋ค. ๋ฐ๋ผ์ ์๋์ฒ๋ผ spring-boot-starter-web์ ์ฌ์ฉํ๋ฉด ์ข ์๋ ๋ชจ๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์๋ง๊ฒ ์ฐพ์์ ํจ๊ป ๊ฐ์ ธ์ค๊ธฐ ๋๋ฌธ์ ์ข ์์ฑ์ด๋ ํธํ ๋ฒ์ ์ ๋ํด ์ ๊ฒฝ ์ธ ํ์๊ฐ ์๋ค. ๊ฐ๋ฐ์๋ ๋จ์ง ์ ํ๋ฆฌ์ผ์ด์ ์ ์คํํ๋ฉด ๋๋ค.
<dependency>
<groupid>org.springframework.boot</groupid>
<artifactid>spring-boot-starter-web</artifactid>
</dependency>
2) Embed Tomcat
์คํ๋ง ๋ถํธ๋ ๋ด์ฅํ ํฐ์บฃ์ ๊ฐ์ง๊ณ ์๊ธฐ ๋๋ฌธ์ ๋ณ๋์ ํฐ์บฃ์ ์ค์ ํ ํ์๊ฐ ์์ด์ก์ผ๋ฉฐ ๊ทธ๋ ๊ธฐ ๋๋ฌธ์ ๋ ๋ฆฝ์ ์ผ๋ก ์คํ ๊ฐ๋ฅํ jar๋ก ์์ฝ๊ฒ ๋ฐฐํฌ๊ฐ ๊ฐ๋ฅํ๋ค.
dzone.com/articles/spring-vs-spring-boot
Spring vs. Spring Boot: A Comparison of These Java Frameworks - DZone Java
In this post, we compare and contrast the two most popular Java frameworks — Spring and Spring Boot — to demonstrate the types of problems that they solve.
dzone.com
msyu1207.tistory.com/entry/Spring-VS-Spring-Boot-์ฐจ์ด์ ์-์์๋ณด์?category=640981
Spring์ ํน์ง๊ณผ Spring Boot์์ ์ฐจ์ด์ ์ ์์๋ณด์
์๋ ํ์ธ์ ๐ ์ ์ ์์ ํ ๊ฐ๋ฐ์ ์ ๋ก๋ ์ ๋๋ค ๐ ์ด๋ฒ ํฌ์คํ ์์๋ โ ์คํ๋ง(Spring) ์ด๋? โ ์คํ๋ง(Spring)์ ํน์ง โ Spring๊ณผ SpringBoot์ ์ฐจ์ด์ ์ ๋ํด ์์๋ณด๊ฒ ์ต๋๋ค ๐ ์คํ๋ง(Spring)๊ณผ
msyu1207.tistory.com