๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

Spring/Boost Course Web

3.1 Spring Core

๋ชจ๋“  ์‹ค์Šต ์ฝ”๋“œ(+์ฃผ์„) ๋งํฌ: ํ”„๋กœ์ ํŠธ๋ช…: diexam01

1) Spring์ด๋ž€?

Spring Framework๋ž€?

img

  • ์—”ํ„ฐํ”„๋ผ์ด์ฆˆ๊ธ‰ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๊ตฌ์ถ•ํ•  ์ˆ˜ ์žˆ๋Š” ๊ฐ€๋ฒผ์šด ์†”๋ฃจ์…˜์ด์ž, ์›์Šค-์Šคํƒ‘-์ˆ(One-Stop-Shop)
  • ์›ํ•˜๋Š” ๋ถ€๋ถ„๋งŒ ๊ฐ€์ ธ๋‹ค ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ๋ชจ๋“ˆํ™”๊ฐ€ ์ž˜ ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.
  • IoC ์ปจํ…Œ์ด๋„ˆ์ž…๋‹ˆ๋‹ค.
  • ์„ ์–ธ์ ์œผ๋กœ ํŠธ๋žœ์žญ์…˜์„ ๊ด€๋ฆฌํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  • ์™„์ „ํ•œ ๊ธฐ๋Šฅ์„ ๊ฐ–์ถ˜ MVC Framework๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.
  • AOP ์ง€์›ํ•ฉ๋‹ˆ๋‹ค.
  • ์Šคํ”„๋ง์€ ๋„๋ฉ”์ธ ๋…ผ๋ฆฌ ์ฝ”๋“œ์™€ ์‰ฝ๊ฒŒ ๋ถ„๋ฆฌ๋  ์ˆ˜ ์žˆ๋Š” ๊ตฌ์กฐ๋กœ ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.

ํ”„๋ ˆ์ž„ ์›Œํฌ ๋ชจ๋“ˆ

  • ์Šคํ”„๋ง ํ”„๋ ˆ์ž„์›Œํฌ๋Š” ์•ฝ 20๊ฐœ์˜ ๋ชจ๋“ˆ๋กœ ๊ตฌ์„ฑ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.
  • ํ•„์š”ํ•œ ๋ชจ๋“ˆ๋งŒ ๊ฐ€์ ธ๋‹ค ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

AOP์™€ ์ธ์ŠคํŠธ๋ฃจ๋ฉ˜ํ…Œ์ด์…˜ (Instrumentation)

  • spring-AOP : AOP ์–ผ๋ผ์ด์–ธ์Šค(Alliance)์™€ ํ˜ธํ™˜๋˜๋Š” ๋ฐฉ๋ฒ•์œผ๋กœ AOP๋ฅผ ์ง€์›ํ•ฉ๋‹ˆ๋‹ค.
  • spring-aspects : AspectJ์™€์˜ ํ†ตํ•ฉ์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.
  • spring-instrument : instrumentation์„ ์ง€์›ํ•˜๋Š” ํด๋ž˜์Šค์™€ ํŠน์ • WAS์—์„œ ์‚ฌ์šฉํ•˜๋Š” ํด๋ž˜์Šค๋กœ ๋” ๊ตฌํ˜„์ฒด๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. ์ฐธ๊ณ ๋กœ BCI(Byte Code Instrumentations)์€ ๋Ÿฐํƒ€์ž„์ด๋‚˜ ๋กœ๋“œ(Load) ๋•Œ ํด๋ž˜์Šค์˜ ๋ฐ”์ดํŠธ ์ฝ”๋“œ์— ๋ณ€๊ฒฝ์„ ๊ฐ€ํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ๋งํ•ฉ๋‹ˆ๋‹ค.

๋ฉ”์‹œ์ง•(Messaging)

  • spring-messaging : ์Šคํ”„๋ง ํ”„๋ ˆ์ž„์›Œํฌ 4๋Š” ๋ฉ”์‹œ์ง€ ๊ธฐ๋ฐ˜ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ์ž‘์„ฑํ•  ์ˆ˜ ์žˆ๋Š” Message, MessageChannel, MessageHandler ๋“ฑ์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. ๋˜ํ•œ, ํ•ด๋‹น ๋ชจ๋“ˆ์—๋Š” ๋ฉ”์†Œ๋“œ์— ๋ฉ”์‹œ์ง€๋ฅผ ๋งตํ•‘ํ•˜๊ธฐ ์œ„ํ•œ ์–ด๋…ธํ…Œ์ด์…˜๋„ ํฌํ•จ๋˜์–ด ์žˆ์œผ๋ฉฐ, Spring MVC ์–ด๋…ธํ…Œ์ด์…˜๊ณผ ์œ ์‚ฌํ•ฉ๋‹ˆ๋‹ค.

Data Access/Integration

  • ๋ฐ์ดํ„ฐ ์—‘์„ธ์Šค/ํ†ตํ•ฉ ๊ณ„์ธต์€ JDBC, ORM, OXM, JMS ๋ฐ ํŠธ๋žœ์žญ์…˜ ๋ชจ๋“ˆ๋กœ ๊ตฌ์„ฑ๋˜์–ด ์žˆ๋‹ค.
  • spring-jdbc : ์ž๋ฐ” JDBCํ”„๋กœ๊ทธ๋ž˜๋ฐ์„ ์‰ฝ๊ฒŒ ํ•  ์ˆ˜ ์žˆ๋„๋ก ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. (์ด ๊ณผ์ •์—์„œ ๋ฐฐ์šฐ๋Š” ๊ฒƒ. ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ๋ฐ์ดํ„ฐ๋ฅผ ๋„ฃ๊ฑฐ๋‚˜ ์ฝ์–ด์˜ฌ ๋•Œ ์‚ฌ์šฉํ•œ๋‹ค)
  • spring-tx : ์„ ์–ธ์  ํŠธ๋žœ์žญ์…˜ ๊ด€๋ฆฌ๋ฅผ ํ•  ์ˆ˜ ์žˆ๋Š” ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. (์ด ๊ณผ์ •์—์„œ ๋ฐฐ์šฐ๋Š” ๋ชจ๋“ˆ)
  • spring-orm : JPA, JDO๋ฐ Hibernate๋ฅผ ํฌํ•จํ•œ ORM API๋ฅผ ์œ„ํ•œ ํ†ตํ•ฉ ๋ ˆ์ด์–ด๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.
  • spring-oxm : JAXB, Castor, XMLBeans, JiBX ๋ฐ XStream๊ณผ ๊ฐ™์€ Object/XML ๋งตํ•‘์„ ์ง€์›ํ•ฉ๋‹ˆ๋‹ค.
  • spring-jms : ๋ฉ”์‹œ์ง€ ์ƒ์„ฑ(producing) ๋ฐ ์‚ฌ์šฉ(consuming)์„ ์œ„ํ•œ ๊ธฐ๋Šฅ์„ ์ œ๊ณต, Spring Framework 4.1๋ถ€ํ„ฐ spring-messaging๋ชจ๋“ˆ๊ณผ์˜ ํ†ตํ•ฉ์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.

์›น(Web)

  • ์›น ๊ณ„์ธต์€ spring-web, spring-webmvc, spring-websocket, spring-webmvc-portlet ๋ชจ๋“ˆ๋กœ ๊ตฌ์„ฑ๋ฉ๋‹ˆ๋‹ค.
  • spring-web : ๋ฉ€ํ‹ฐ ํŒŒํŠธ ํŒŒ์ผ ์—…๋กœ๋“œ, ์„œ๋ธ”๋ฆฟ ๋ฆฌ์Šค๋„ˆ ๋“ฑ ์›น ์ง€ํ–ฅ ํ†ตํ•ฉ ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•œ๋‹ค. HTTPํด๋ผ์ด์–ธํŠธ์™€ Spring์˜ ์›๊ฒฉ ์ง€์›์„ ์œ„ํ•œ ์›น ๊ด€๋ จ ๋ถ€๋ถ„์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. (์ด ๊ณผ์ •์—์„œ ๋ฐฐ์šฐ๋Š” ๋ชจ๋“ˆ)
  • spring-webmvc : Web-Servlet ๋ชจ๋“ˆ์ด๋ผ๊ณ ๋„ ๋ถˆ๋ฆฌ๋ฉฐ, Spring MVC ๋ฐ REST ์›น ์„œ๋น„์Šค ๊ตฌํ˜„์„ ํฌํ•จํ•ฉ๋‹ˆ๋‹ค. (์ด ๊ณผ์ •์—์„œ ๋ฐฐ์šฐ๋Š” ๋ชจ๋“ˆ)
  • spring-websocket : ์›น ์†Œ์ผ“์„ ์ง€์›ํ•ฉ๋‹ˆ๋‹ค.
  • spring-webmvc-portlet : ํฌํ‹€๋ฆฟ ํ™˜๊ฒฝ์—์„œ ์‚ฌ์šฉํ•  MVC ๊ตฌํ˜„์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.

 

2) Spring IoC/DI ์ปจํ…Œ์ด๋„ˆ

์ปจํ…Œ์ด๋„ˆ(Container)

์ปจํ…Œ์ด๋„ˆ๋Š” ์ธ์Šคํ„ด์Šค์˜ ์ƒ๋ช…์ฃผ๊ธฐ๋ฅผ ๊ด€๋ฆฌํ•˜๋ฉฐ, ์ƒ์„ฑ๋œ ์ธ์Šคํ„ด์Šค์—๊ฒŒ ์ถ”๊ฐ€์ ์ธ ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.

์˜ˆ๋ฅผ ๋“ค์–ด, Servlet์„ ์‹คํ–‰ํ•ด์ฃผ๋Š” WAS๋Š” Servlet ์ปจํ…Œ์ด๋„ˆ๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๋‹ค๊ณ  ๋งํ•ฉ๋‹ˆ๋‹ค.

WAS๋Š” ์›น ๋ธŒ๋ผ์šฐ์ €๋กœ๋ถ€ํ„ฐ ์„œ๋ธ”๋ฆฟ URL์— ํ•ด๋‹นํ•˜๋Š” ์š”์ฒญ์„ ๋ฐ›์œผ๋ฉด, ์„œ๋ธ”๋ฆฟ์„ ๋ฉ”๋ชจ๋ฆฌ์— ์˜ฌ๋ฆฐ ํ›„ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.

๊ฐœ๋ฐœ์ž๊ฐ€ ์„œ๋ธ”๋ฆฟ ํด๋ž˜์Šค๋ฅผ ์ž‘์„ฑํ–ˆ์ง€๋งŒ, ์‹ค์ œ๋กœ ๋ฉ”๋ชจ๋ฆฌ์— ์˜ฌ๋ฆฌ๊ณ  ์‹คํ–‰ํ•˜๋Š” ๊ฒƒ์€ WAS๊ฐ€ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” Servlet ์ปจํ…Œ์ด๋„ˆ์ž…๋‹ˆ๋‹ค.

Servlet์ปจํ…Œ์ด๋„ˆ๋Š” ๋™์ผํ•œ ์„œ๋ธ”๋ฆฟ์— ํ•ด๋‹นํ•˜๋Š” ์š”์ฒญ์„ ๋ฐ›์œผ๋ฉด, ๋˜ ๋ฉ”๋ชจ๋ฆฌ์— ์˜ฌ๋ฆฌ์ง€ ์•Š๊ณ  ๊ธฐ์กด์— ๋ฉ”๋ชจ๋ฆฌ์— ์˜ฌ๋ผ๊ฐ„ ์„œ๋ธ”๋ฆฟ์„ ์‹คํ–‰ํ•˜์—ฌ ๊ทธ ๊ฒฐ๊ณผ๋ฅผ ์›น ๋ธŒ๋ผ์šฐ์ €์—๊ฒŒ ์ „๋‹ฌํ•ฉ๋‹ˆ๋‹ค.

์ปจํ…Œ์ด๋„ˆ๋Š” ๋ณดํ†ต ์ธ์Šคํ„ด์Šค์˜ ์ƒ๋ช…์ฃผ๊ธฐ๋ฅผ ๊ด€๋ฆฌํ•˜๋ฉฐ, ์ƒ์„ฑ๋œ ์ธ์Šคํ„ด์Šค๋“ค์—๊ฒŒ ์ถ”๊ฐ€์ ์ธ ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•˜๋Š” ๊ฒƒ์„ ๋งํ•ฉ๋‹ˆ๋‹ค.

IoC(Inversion of Control)

๊ฐ์ฒด๋ฅผ ๋Œ€์‹  ์ƒ์„ฑํ•ด์ฃผ๊ณ  ์‹ฑ๊ธ€ํ„ด์œผ๋กœ ๊ด€๋ฆฌํ•ด์ฃผ๋Š” ๊ธฐ๋Šฅ

์ปจํ…Œ์ด๋„ˆ๊ฐ€ ์ฝ”๋“œ ๋Œ€์‹  ์˜ค๋ธŒ์ ํŠธ์˜ ์ œ์–ด๊ถŒ์„ ๊ฐ–๊ณ  ์žˆ์–ด IoC(์ œ์–ด์˜ ์—ญ์ „)์ด๋ผ ํ•ฉ๋‹ˆ๋‹ค.

์˜ˆ๋ฅผ ๋“ค์–ด, ์„œ๋ธ”๋ฆฟ ํด๋ž˜์Šค๋Š” ๊ฐœ๋ฐœ์ž๊ฐ€ ๋งŒ๋“ค์ง€๋งŒ, ๊ทธ ์„œ๋ธ”๋ฆฟ์˜ ๋ฉ”์†Œ๋“œ๋ฅผ ์•Œ๋งž๊ฒŒ ํ˜ธ์ถœํ•˜๋Š” ๊ฒƒ์€ WAS์ž…๋‹ˆ๋‹ค.

์ด๋ ‡๊ฒŒ ๊ฐœ๋ฐœ์ž๊ฐ€ ๋งŒ๋“  ์–ด๋–ค ํด๋ž˜์Šค๋‚˜ ๋ฉ”์†Œ๋“œ๋ฅผ ๋‹ค๋ฅธ ํ”„๋กœ๊ทธ๋žจ์ด ๋Œ€์‹  ์‹คํ–‰ํ•ด์ฃผ๋Š” ๊ฒƒ์„ ์ œ์–ด์˜ ์—ญ์ „์ด๋ผ๊ณ  ํ•ฉ๋‹ˆ๋‹ค.

"๊ณต์žฅ์„ ๋งค๋ฒˆ ๋‚ด๊ฐ€ ๋งŒ๋“ค์–ด์•ผ ๋˜๋Š” ๊ฑฐ ๋˜๊ฒŒ ๊ท€์ฐฎ์€ ์ผ์ผ ํ…๋ฐ Spring์ด ๊ทธ ์ผ์„ ๋Œ€์‹ ํ•ด์ฃผ๋Š” ๊ฑฐ์˜ˆ์š”.

Spring์ด ๊ฐ–๊ณ  ์žˆ๋Š” Bean Factory๋ผ๋“ ๊ฐ€ Application Context ๊ฐ™์€ ๊ฒƒ์ด ์ด๋Ÿฐ ๊ณต์žฅ์˜ ์—ญํ• ์„ ํ•ด์ค„ ๊ฑฐ๋‹ค."

DI(Dependency Injection)

DI๋Š” ์˜์กด์„ฑ ์ฃผ์ž…์ด๋ž€ ๋œป์„ ๊ฐ€์ง€๊ณ  ์žˆ์œผ๋ฉฐ, ํด๋ž˜์Šค ์‚ฌ์ด์˜ ์˜์กด ๊ด€๊ณ„๋ฅผ ๋นˆ(Bean) ์„ค์ • ์ •๋ณด๋ฅผ ๋ฐ”ํƒ•์œผ๋กœ ์ปจํ…Œ์ด๋„ˆ๊ฐ€ ์ž๋™์œผ๋กœ ์—ฐ๊ฒฐํ•ด์ฃผ๋Š” ๊ฒƒ์„ ๋งํ•ฉ๋‹ˆ๋‹ค.

๊ณต์žฅ์ด ์ƒ์„ฑํ•ด์ค€ ๊ฐ์ฒด๋ฅผ ์–ด๋–ป๊ฒŒ ์“ธ ๊ฑฐ์˜ˆ์š” ํ•˜๋Š” ๊ฒŒ ์ค‘์š”ํ•  ํ…๋ฐ์š”. DI๊ฐ€ ํ•ด๋‹น ๊ฐ์ฒด๋ฅผ ์ฃผ์ž…๋ฐ›๋Š” ๋ฐฉ๋ฒ• ์ค‘์— ํ•˜๋‚˜๋‹ค

DI๊ฐ€ ์ ์šฉ ์•ˆ ๋œ ์˜ˆ: ๊ฐœ๋ฐœ์ž๊ฐ€ ์ง์ ‘ ์ธ์Šคํ„ด์Šค๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

class ์—”์ง„ {  
}
class ์ž๋™์ฐจ {
  ์—”์ง„ v5 = new ์—”์ง„();
}

img

Spring์—์„œ DI๊ฐ€ ์ ์šฉ๋œ ์˜ˆ

์—”์ง„ type์˜ v5๋ณ€์ˆ˜์— ์•„์ง ์ธ์Šคํ„ด์Šค๊ฐ€ ํ• ๋‹น๋˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค.

์–ด๋””์—์„œ๋„ ์—”์ง„์— ๋Œ€ํ•œ ์ƒ์„ฑ์„ ํ•˜์ง€ ์•Š์•˜๋Š”๋ฐ ์ปจํ…Œ์ด๋„ˆ๊ฐ€ v5๋ณ€์ˆ˜์— ์ธ์Šคํ„ด์Šค๋ฅผ ํ• ๋‹นํ•ด์ฃผ๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

@Component
class ์—”์ง„ { 
}

@Component
class ์ž๋™์ฐจ {
  @Autowired
  ์—”์ง„ v5;
}

img

Spring์—์„œ ์ œ๊ณตํ•˜๋Š” IoC/DI ์ปจํ…Œ์ด๋„ˆ

  • BeanFactory : IoC/DI์— ๋Œ€ํ•œ ๊ธฐ๋ณธ ๊ธฐ๋Šฅ์„ ๊ฐ€์ง€๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

  • ApplicationContext : BeanFactory์˜ ๋ชจ๋“  ๊ธฐ๋Šฅ์„ ํฌํ•จํ•˜๋ฉฐ, ์ผ๋ฐ˜์ ์œผ๋กœ BeanFactory๋ณด๋‹ค ์ถ”์ฒœ๋ฉ๋‹ˆ๋‹ค. ํŠธ๋žœ์žญ์…˜์ฒ˜๋ฆฌ, AOP๋“ฑ์— ๋Œ€ํ•œ ์ฒ˜๋ฆฌ๋ฅผ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. BeanPostProcessor, BeanFactoryPostProcessor๋“ฑ์„ ์ž๋™์œผ๋กœ ๋“ฑ๋กํ•˜๊ณ , ๊ตญ์ œํ™” ์ฒ˜๋ฆฌ, ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜ ์ด๋ฒคํŠธ ๋“ฑ์„ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์Šต๋‹ˆ๋‹ค.

  • BeanPostProcessor : ์ปจํ…Œ์ด๋„ˆ์˜ ๊ธฐ๋ณธ๋กœ์ง์„ ์˜ค๋ฒ„๋ผ์ด๋”ฉํ•˜์—ฌ ์ธ์Šคํ„ด์Šคํ™” ์™€ ์˜์กด์„ฑ ์ฒ˜๋ฆฌ ๋กœ์ง ๋“ฑ์„ ๊ฐœ๋ฐœ์ž๊ฐ€ ์›ํ•˜๋Š” ๋Œ€๋กœ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•ฉ๋‹ˆ๋‹ค.

  • BeanFactoryPostProcessor : ์„ค์ •๋œ ๋ฉ”ํƒ€๋ฐ์ดํ„ฐ๋ฅผ ์ปค์Šคํ„ฐ๋งˆ์ด์ง• ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.


3) xmlํŒŒ์ผ์„ ์ด์šฉํ•œ ์„ค์ •

์—๋Ÿฌ์‚ฌํ•ญ

Maven์œผ๋กœ Javaํ”„๋กœ์ ํŠธ ๋งŒ๋“ค๊ธฐ

Archetype์€ Maven ํ”„๋กœ์ ํŠธ์—์„œ ์ œ๊ณตํ•ด์ฃผ๋Š” ํ…œํ”Œ๋ฆฟ์ด๋‹ค.

์–ด๋–ค ๊ฒƒ์„ ์ง€์ •ํ•˜๋Š๋ƒ์— ๋”ฐ๋ผ์„œ ํ”„๋กœ์ ํŠธ ๊ตฌ์กฐ๊ฐ€ ๋‹ฌ๋ผ์ง€๊ณ  ์˜ˆ์ œ ๋“ฑ์ด ๋“ค์–ด์žˆ์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

pom.xml ํŒŒ์ผ์— JDK๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•œ ํ”Œ๋Ÿฌ๊ทธ์ธ ์„ค์ •์„ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <spring.version>4.3.14.RELEASE</spring.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <pluginManagement>
            <plugins>
                <!-- jdk 1.8 ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด. -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.6.1</version>
                    <configuration>
                        <source>1.8</source>
                        <target>1.8</target>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

App.java๊ณผ AppTest.java์œผ๋กœ ์ž˜ ์ž‘๋™ํ•˜๋Š”์ง€ ํ™•์ธํ•ด๋ณธ๋‹ค.

Bean class๋ž€?

์˜ˆ์ „์—๋Š” Visualํ•œ ์ปดํฌ๋„ŒํŠธ๋ฅผ Bean์ด๋ผ๊ณ  ๋ถˆ๋ €์ง€๋งŒ, ๊ทผ๋ž˜ ๋“ค์–ด์„œ๋Š” ์ผ๋ฐ˜์ ์ธ Javaํด๋ž˜์Šค๋ฅผ Beanํด๋ž˜์Šค๋ผ๊ณ  ๋ณดํ†ต ๋งํ•ฉ๋‹ˆ๋‹ค.

Beanํด๋ž˜์Šค์˜ 3๊ฐ€์ง€ ํŠน์ง•์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

  • ๊ธฐ๋ณธ์ƒ์„ฑ์ž๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.
  • ํ•„๋“œ๋Š” privateํ•˜๊ฒŒ ์„ ์–ธํ•ฉ๋‹ˆ๋‹ค.
  • getter, setter ๋ฉ”์†Œ๋“œ๋ฅผ ๊ฐ€์ง‘๋‹ˆ๋‹ค.
  • getName() setName() ๋ฉ”์†Œ๋“œ๋ฅผ name ํ”„๋กœํผํ‹ฐ(property)๋ผ๊ณ  ํ•ฉ๋‹ˆ๋‹ค. (์šฉ์–ด ์ค‘์š”)

Spring์ปจํ…Œ์ด๋„ˆ๊ฐ€ ๊ด€๋ฆฌํ•˜๋Š” ๊ฐ์ฒด๋ฅผ ๋นˆ(Bean)์ด๋ผ๊ณ  ๋งํ•ฉ๋‹ˆ๋‹ค.

(์ง์ ‘ new์—ฐ์‚ฐ์ž๋กœ ์ƒ์„ฑํ•ด์„œ ์‚ฌ์šฉํ•˜๋Š” ๊ฐ์ฒด๋Š” ๋นˆ(Bean)์ด๋ผ๊ณ  ๋งํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.)

Spring์€ ๋นˆ์„ ์ƒ์„ฑํ•  ๋•Œ ๊ธฐ๋ณธ์ ์œผ๋กœ ์‹ฑ๊ธ€ํ†ค(Singleton) ๊ฐ์ฒด๋กœ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

์‹ฑ๊ธ€ํ†ค์ด๋ž€ ๋ฉ”๋ชจ๋ฆฌ์— ํ•˜๋‚˜๋งŒ ์ƒ์„ฑํ•œ๋‹ค๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค.

UserBean.java

public class UserBean {        
        private String name;
        private int age;
        private boolean male;

        public UserBean() {    }
        public UserBean(String name, int age, boolean male) {
            this.name = name; this.age = age; this.male = male;
        }
        getter, setter ์ƒ๋žต
    }

Spring Bean Factory๋ฅผ ์ด์šฉํ•˜์—ฌ Bean๊ฐ์ฒด ์ด์šฉํ•˜๊ธฐ

  1. pom.xml ํŒŒ์ผ์— Spring ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.

https://mvnrepository.com/artifact/org.springframework/spring-context

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context</artifactId>
    <version>${spring.version}</version>
</dependency>

์ฐธ๊ณ ๋กœ context๊ฐ€ ๊ณต์žฅ์ด๋‹ค.

maven repository์— ์›ํ•˜๋Š” ์˜์กด์„ฑ(spring context)์„ ๊ฒ€์ƒ‰ํ•˜๊ณ  spring version ์Šคํ”„๋ง๋ฒ„์ „๊ณผ dependency ๋ถ€๋ถ„์„ ๋ณต์‚ฌํ•˜์—ฌ ๋ถ™์—ฌ๋„ฃ์œผ๋ฉด ๋œ๋‹ค.

  1. ์ถ”๊ฐ€๋œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.

maven dependencies ํด๋”์— ์ถ”๊ฐ€๋œ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

  1. src/main ํด๋” ๋ฐ‘์— resources ์†Œ์Šค ํด๋”๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค. ํ•ด๋‹น ํด๋”์— applicationContext.xml ํŒŒ์ผ์„ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

applicationContext.xml

์„ค์ •์„ ๋‹ด๊ณ  ์žˆ๋Š” ํŒŒ์ผ๋“ค์„ applicationContext.xml๋กœ ํ•œ๋‹ค.

์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ context(๊ณต์žฅ)๋“ค์—๊ฒŒ ์„ค์ •๋“ค์„ ์•Œ๋ ค์ฃผ๋„๋ก ํ•œ๋‹ค.

<?xml version="1.0" encoding="UTF-8"?>
<!-- xml ํŒŒ์ผ์€ ๋ฐ˜๋“œ์‹œ ๋‚˜ xml์ด๊ณ , ๋ฒ„์ „์€ ๋ญ๊ณ , ์บ๋ฆญํ„ฐ ์…‹์€ ๋ญ˜ ์“ธ ๊ฑฐ์•ผ๋ฅผ ์•Œ๋ ค์ค˜์•ผํ•ด -->

<!-- ๋ฃจํŠธ element๋Š” beans ๋ผ๋Š” element์—์š” xml ํŒŒ์ผ๋กœ Spring ์„ค์ • ํŒŒ์ผ์„ ๋งŒ๋“ค๊ฒŒ ๋˜๋ฉด ๊ฐ€์žฅ ๋ฐ”๊นฅ์ชฝ ํƒœ๊ทธ, ์ด๊ฒƒ์„ ๋ฃจํŠธ element๋ผ๊ณ  ํ•˜๊ฑฐ๋“ ์š” ์ด๊ฒŒ ๋ฐ˜๋“œ์‹œ beans๋กœ ๋˜์–ด์žˆ์–ด์•ผ ํ•œ๋‹ค. ๊ทธ๋ฆฌ๊ณ  xml ์Šคํ‚ค๋งˆ์— ๋Œ€ํ•œ ์„ค์ •๋„ ๋˜์–ด์žˆ์–ด์•ผํ•ด์š”. ํ•ด๋‹น ์„ค์ • ํŒŒ์ผ์€ spring ์ปจํ…Œ์ด๋„ˆ๊ฐ€ ์ฝ์–ด๋“ค์ด๋Š”๋ฐ beans ํƒœ๊ทธ ์•ˆ์— ์•„๋ฌด๊ฒƒ๋„ ์—†์œผ๋ฉด ๋‹น์—ฐํžˆ ์•„๋ฌด ์ผ๋„ ์•ˆํ•˜๊ฒ ์ฃ . -->
<beans xmlns="http://www.springframework.org/schema/beans"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

applicationContext.xmlํŒŒ์ผ์— ์ด์–ด์„œ bean ํƒœ๊ทธ๋ฅผ ํ•˜๋‚˜ ์ž…๋ ฅํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

 <bean id="userBean" class="kr.or.connect.diexam01.UserBean"></bean>

์œ„์˜ ํƒœ๊ทธ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์˜๋ฏธ๋ฅผ ๊ฐ€์ง‘๋‹ˆ๋‹ค.

UserBean userBean = new UserBean();

ApplicationContext๋ฅผ ์ด์šฉํ•ด์„œ ์„ค์ •ํŒŒ์ผ์„ ์ฝ์–ด๋“ค์—ฌ ์‹คํ–‰ํ•˜๊ธฐ

 

ApplicationContextExam01.java

 

 

main ๋ฐ‘์— ์žˆ๋Š” resources ํด๋”์—์„œ ์ƒ์„ฑํ•œ xml ํŒŒ์ผ์€ ์ž๋™์œผ๋กœ classpath๋กœ ์ง€์ •์ด ๋œ๋‹ค. ๊ทธ๋ ‡๊ธฐ ๋•Œ๋ฌธ์— ClassPathXmlApplicationContext ๋กœ ์ฝ์–ด์„œ ์‚ฌ์šฉํ•  ์ˆ˜๊ฐ€ ์žˆ๋‹ค.

ClassPathXmlApplicationContext ์ธ์Šคํ„ด์Šค๊ฐ€ ์ƒ์„ฑ๋  ๋•Œ ์ƒ์„ฑ์ž ํŒŒ๋ผ๋ฏธํ„ฐ๋กœ ์ง€์ •๋œ ์„ค์ • ํŒŒ์ผ์„ ์ฝ์–ด๋“ค์ธ ํ›„์— ๊ทธ ์•ˆ์— ์„ ์–ธ๋œ bean๋“ค์„ ๋ชจ๋‘ ๋ฉ”๋ชจ๋ฆฌ์— ์˜ฌ๋ ค์ค€๋‹ค.

DI ํ™•์ธํ•˜๊ธฐ

์ด๋ฒˆ์—๋Š” DI ์ฆ‰ ์˜์กด์„ฑ ์ฃผ์ž…์„ ํ™•์ธํ•ด๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

Car์™€ Engine์ด๋ผ๋Š” ํด๋ž˜์Šค 2๊ฐœ๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

Engine.java

Car.java

์œ„์˜ Car ํด๋ž˜์Šค๊ฐ€ ์ œ๋Œ€๋กœ ๋™์ž‘ํ•˜๋„๋ก ํ•˜๋ ค๋ฉด ๋ณดํ†ต ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ฝ”๋“œ๊ฐ€ ์ž‘์„ฑ๋˜์•ผ ํ•ฉ๋‹ˆ๋‹ค.

Engine e = new Engine();
Car c = new Car();
c.setEngine(e);
c.run();

1, 2 ๋ฒˆ์งธ ์ค„์„ Spring ์ปจํ…Œ์ด๋„ˆ์—๊ฒŒ ๋งก๊ธฐ๊ธฐ ์œ„ํ•ด ์„ค์ •ํŒŒ์ผ์— ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ฝ”๋“œ๋ฅผ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค.

<bean id="e" class="kr.or.connect.diexam01.Engine"></bean>
<bean id="car" class="kr.or.connect.diexam01.Car">
<property name="engine" ref="e"></property>
</bean>

์ฆ‰, ์œ„์˜ XML์„ค์ •์€ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์˜๋ฏธ๋ฅผ ๊ฐ€์ง‘๋‹ˆ๋‹ค.

Engine e = new Engine();
Car c = new Car();
c.setEngine( e );

 

์ด๋ฒˆ์—” ์œ„์˜ ์„ค์ • ํŒŒ์ผ์„ ์ฝ์–ด๋“ค์—ฌ ์‹คํ–‰ํ•˜๋Š” ApplicationContextExam02.java๋ฅผ ์ž‘์„ฑํ•ด๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

package kr.or.connect.diexam01;

import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class ApplicationContextExam02 {
    public static void main(String[] args) {
        // ClassPath์—์„œ ์„ค์ •์„ ์ฝ์–ด์˜ด
        ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");

        Car car = (Car) ac.getBean("c"); // ๋“ฑ๋กํ–ˆ๋˜ bean id ์ฃผ๊ธฐ
        car.run();

        ((ConfigurableApplicationContext)ac).close();
        }
}

4) Java Config๋ฅผ ์ด์šฉํ•œ ์„ค์ •

 

์šฐ๋ฆฌ๋Š” ์•ž์—์„œ xml์„ ์ด์šฉํ•œ ์„ค์ •์— ๋Œ€ํ•ด ์‚ดํŽด๋ณด์•˜์Šต๋‹ˆ๋‹ค. ์ด๋ฒˆ ์‹œ๊ฐ„์—” xml ์„ค์ •์„ ๋Œ€์ฒดํ•  ์ˆ˜ ์žˆ๋Š” Java Config์— ๋Œ€ํ•ด ๋ฐฐ์›Œ๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. Java Config๋ž€ ๋ง๊ทธ๋Œ€๋กœ ์ž๋ฐ” ํด๋ž˜์Šค ํŒŒ์ผ์„ ์„ค์ • ํŒŒ์ผ๋กœ ์‚ฌ์šฉ์„ ํ•˜๊ฒ ๋‹ค๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค. xml์„ค์ •๊ณผ ๋น„๊ตํ•ด์„œ Java Config๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ์ด์œ ๋Š”, ํด๋ž˜์Šค์˜ ๊ฒฝ์šฐ ์ดํด๋ฆฝ์Šค๋‚˜ ์ธํ…”๋ฆฌJ์™€ ๊ฐ™์€ IDE์—์„œ ์˜คํƒ€ ๋“ฑ์„ ๋ฐœ๊ฒฌํ•˜๊ธฐ ์‰ฝ๊ณ , ์ž๋™์™„์„ฑ ๋“ฑ์„ ์ง€์›ํ•ด์„œ ํŽธ๋ฆฌํ•˜๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค.

์Šคํ”„๋ง์—์„œ๋Š” Java Config๋กœ ์‚ฌ์šฉํ•˜๋Š” ํด๋ž˜์Šค์—๋Š” @Configuration์ด๋ผ๋Š” ์–ด๋…ธํ…Œ์ด์…˜์„ ๋ถ™์—ฌ์„œ ํ‘œ์‹œ๋ฅผ ํ•ฉ๋‹ˆ๋‹ค.

Java config๋ฅผ ์ด์šฉํ•œ ์„ค์ •์„ ์œ„ํ•œ ์–ด๋…ธํ…Œ์ด์…˜

@Configuration

  • ์Šคํ”„๋ง ์„ค์ • ํด๋ž˜์Šค๋ฅผ ์„ ์–ธํ•˜๋Š” ์–ด๋…ธํ…Œ์ด์…˜

@Bean

  • bean์„ ์ •์˜ํ•˜๋Š” ์–ด๋…ธํ…Œ์ด์…˜

@ComponentScan

  • @Controller, @Service, @Repository, @Component ์–ด๋…ธํ…Œ์ด์…˜์ด ๋ถ™์€ ํด๋ž˜์Šค๋ฅผ ์ฐพ์•„ ์ปจํ…Œ์ด๋„ˆ์— ๋“ฑ๋ก

@Component

  • ์ปดํฌ๋„ŒํŠธ ์Šค์บ”์˜ ๋Œ€์ƒ์ด ๋˜๋Š” ์• ๋…ธํ…Œ์ด์…˜ ์ค‘ ํ•˜๋‚˜๋กœ์จ ์ฃผ๋กœ ์œ ํ‹ธ, ๊ธฐํƒ€ ์ง€์› ํด๋ž˜์Šค์— ๋ถ™์ด๋Š” ์–ด๋…ธํ…Œ์ด์…˜

@Autowired

  • ์ฃผ์ž… ๋Œ€์ƒ์ด๋˜๋Š” bean์„ ์ปจํ…Œ์ด๋„ˆ์— ์ฐพ์•„ ์ฃผ์ž…ํ•˜๋Š”(๊ฐ์ฒด์ƒ์„ฑ) ์–ด๋…ธํ…Œ์ด์…˜

Java Config๋ฅผ ์ด์šฉํ•ด ์„ค์ •ํ•˜๊ธฐ

ApplicationConfig.java

package kr.or.connect.diexam01;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

//xml ์„ค์ •์„ ๋Œ€์ฒดํ•  ์ˆ˜ ์žˆ๋Š” Java Config
//์ž๋ฐ” ํด๋ž˜์Šค ํŒŒ์ผ์„ ์„ค์ • ํŒŒ์ผ๋กœ ์‚ฌ์šฉ

@Configuration
public class ApplicationConfig {
    @Bean
    public Car car(Engine e) {
        Car c = new Car();
        c.setEngine(e);
        return c;
    }

    @Bean
    public Engine engine() {
        return new Engine();
    }
}

@Configuration ์€ ์Šคํ”„๋ง ์„ค์ • ํด๋ž˜์Šค๋ผ๋Š” ์˜๋ฏธ๋ฅผ ๊ฐ€์ง‘๋‹ˆ๋‹ค.

JavaConfig๋กœ ์„ค์ •์„ ํ•  ํด๋ž˜์Šค ์œ„์—๋Š” @Configuration๊ฐ€ ๋ถ™์–ด ์žˆ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

ApplicationContext์ค‘์—์„œ AnnotationConfigApplicationContext๋Š” JavaConfigํด๋ž˜์Šค๋ฅผ ์ฝ์–ด๋“ค์—ฌ IoC์™€ DI๋ฅผ ์ ์šฉํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

์ด๋•Œ ์„ค์ •ํŒŒ์ผ ์ค‘์— @Bean์ด ๋ถ™์–ด ์žˆ๋Š” ๋ฉ”์†Œ๋“œ๋“ค์„ AnnotationConfigApplicationContext๋Š” ์ž๋™์œผ๋กœ ์‹คํ–‰ํ•˜์—ฌ ๊ทธ ๊ฒฐ๊ณผ๋กœ ๋ฆฌํ„ดํ•˜๋Š” ๊ฐ์ฒด๋“ค์„ ๊ธฐ๋ณธ์ ์œผ๋กœ ์‹ฑ๊ธ€ํ„ด์œผ๋กœ ๊ด€๋ฆฌ๋ฅผ ํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

 

ApplicationContextExam03.java

package kr.or.connect.diexam01;

import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

public class ApplicationContextExam03 {
    public static void main(String[] args) {
        // ์„ค์ •์„ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ํด๋ž˜์Šค๋ฅผ ์ฝ์–ด๋“ค์ด๋ฉด ๋จ. ํด๋ž˜์Šค ํŒŒ์ผ์„ ์ฝ๋„๋ก.
        ApplicationContext ac = new AnnotationConfigApplicationContext(ApplicationConfig.class);

        Car car = (Car) ac.getBean(Car.class); // "๋ฉ”์„œ๋“œ ์ด๋ฆ„" ์•„๋‹˜ Car์˜ ํด๋ž˜์Šค๋ฅผ ์ฃผ์„ธ์š”
        car.run();

        ((ConfigurableApplicationContext)ac).close();
        }


}

ํŒŒ๋ผ๋ฏธํ„ฐ๋กœ ์š”์ฒญํ•˜๋Š” class ํƒ€์ž…์œผ๋กœ ์ง€์ • ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

Car car = ac.getBean(Car.class);


ApplicationConfig2.java

package kr.or.connect.diexam01;

import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

@Configuration
@ComponentScan("kr.or.connect.diexam01")
public class ApplicationConfig2 {

}

๊ธฐ์กด JavaConfig์—์„œ ๋นˆ์„ ์ƒ์„ฑํ•˜๋Š” ๋ฉ”์†Œ๋“œ๋ฅผ ๋ชจ๋‘ ์ œ๊ฑฐํ–ˆ์Šต๋‹ˆ๋‹ค.

๋‹จ, @Configuration์•„๋ž˜์— @ComponentScan์ด๋ผ๋Š” ์–ด๋…ธํ…Œ์ด์…˜์„ ์ถ”๊ฐ€ํ–ˆ์Šต๋‹ˆ๋‹ค.

@ComponentScan์–ด๋…ธํ…Œ์ด์…˜์€ ํŒŒ๋ผ๋ฏธํ„ฐ๋กœ ๋“ค์–ด์˜จ ํŒจํ‚ค์ง€ ์ดํ•˜์—์„œ @Controller, @Service, @Repository, @Component ์–ด๋…ธํ…Œ์ด์…˜์ด ๋ถ™์–ด ์žˆ๋Š” ํด๋ž˜์Šค๋ฅผ ์ฐพ์•„ ๋ฉ”๋ชจ๋ฆฌ์— ๋ชฝ๋•… ์˜ฌ๋ ค์ค๋‹ˆ๋‹ค.

๊ธฐ์กด์˜ Carํด๋ž˜์Šค์™€ Engineํด๋ž˜์Šค ์œ„์— @Component๋ฅผ ๋ถ™์ด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

์ˆ˜์ •๋œ JavaConfig๋ฅผ ์ฝ์–ด๋“ค์—ฌ ์‹คํ–‰ํ•˜๋Š” ํด๋ž˜์Šค๋ฅผ ๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

 

ApplicationContextExam04.java

package kr.or.connect.diexam01;

import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

public class ApplicationContextExam04 {
    public static void main(String[] args) {
        // ์„ค์ •์„ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ํด๋ž˜์Šค๋ฅผ ์ฝ์–ด๋“ค์ด๋ฉด ๋จ. ํด๋ž˜์Šค ํŒŒ์ผ์„ ์ฝ๋„๋ก.
        ApplicationContext ac = new AnnotationConfigApplicationContext(ApplicationConfig2.class);

        Car car = (Car) ac.getBean(Car.class); // "๋ฉ”์„œ๋“œ ์ด๋ฆ„" ์•„๋‹˜ Car์˜ ํด๋ž˜์Šค๋ฅผ ์ฃผ์„ธ์š”
        car.run();

        ((ConfigurableApplicationContext)ac).close();
        }    
}

์ •๋ฆฌ:

Spring์—์„œ ์‚ฌ์šฉํ•˜๊ธฐ์— ์•Œ๋งž๊ฒŒ @Controller, @Service, @Repository, @Component ์–ด๋…ธํ…Œ์ด์…˜์ด ๋ถ™์–ด ์žˆ๋Š” ๊ฐ์ฒด๋“ค์€ ComponentScan์„ ์ด์šฉํ•ด์„œ ์ฝ์–ด๋“ค์—ฌ ๋ฉ”๋ชจ๋ฆฌ์— ์˜ฌ๋ฆฌ๊ณ  DI๋ฅผ ์ฃผ์ž…ํ•˜๋„๋ก ํ•˜๊ณ , ์ด๋Ÿฌํ•œ ์–ด๋…ธํ…Œ์ด์…˜์ด ๋ถ™์–ด ์žˆ์ง€ ์•Š์€ ๊ฐ์ฒด๋Š” @Bean์–ด๋…ธํ…Œ์ด์…˜์„ ์ด์šฉํ•˜์—ฌ ์ง์ ‘ ์ƒ์„ฑํ•ด์ฃผ๋Š” ๋ฐฉ์‹์œผ๋กœ ํด๋ž˜์Šค๋“ค์„ ๊ด€๋ฆฌํ•˜๋ฉด ํŽธ๋ฆฌํ•ฉ๋‹ˆ๋‹ค.

'Spring > Boost Course Web' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

4.1 Spring MVC  (0) 2020.11.19
3.3 Spring JDBC  (0) 2020.11.19
3.2 Spring Test  (0) 2020.11.19
2.6 JSTL & EL  (0) 2020.11.19
2.5 Scope  (0) 2020.11.19
2.4 JSP  (0) 2020.11.19