๋ฐ˜์‘ํ˜•

AOP ๊ฐ€ ์ ์šฉ๋œ ํด๋ž˜์Šค์—์„œ(=ํฌ์ธํŠธ์ปท์˜ ์˜ํ–ฅ์„ ๋ฐ›์€ ํด๋ž˜์Šค) ํ”„๋ก์‹œ๊ฐ€ ์ ์šฉ์•ˆ๋˜๋Š” ์ƒํ™ฉ์ด ์žˆ์—ˆ์Œ!

SampleService ํด๋ž˜์Šค์˜ sample() ๋ฉ”์†Œ๋“œ ๋‚ด์— sampleRecall1(), sampleRecall2() ๋Š” ๋ชจ๋‘ AOP ์˜ ์˜ํ–ฅ์„ ๋ฐ›์„๊ฑฐ๋ผ ์ƒ๊ฐํ–ˆ๋Š”๋ฐ, ๊ทธ๋ ‡์ง€๊ฐ€ ์•Š์•˜์Œ!
์ด์œ ๋Š”, AOP๊ฐ€ ํ”„๋ก์‹œ ๊ธฐ๋ฐ˜์ด์˜€๊ธฐ ๋•Œ๋ฌธ์ด์˜€์Œ!

ํ”„๋ก์‹œ ๊ฐœ๋…์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ, ํ”„๋ก์‹œ ํด๋ž˜์Šค(SampleServiceV2ProcxyImpl)๊ฐ€ ํ•ต์‹ฌ๊ธฐ๋Šฅ ํด๋ž˜์Šค(SampleServiceV2)๋ฅผ ์ฃผ์ž…๋ฐ›์•„ ํ”„๋ก์‹œ ํด๋ž˜์Šค์˜ ๋ฉ”์†Œ๋“œ(SampleServiceV2ProcxyImpl ์˜ sample())๋ฅผ ํ˜ธ์ถœํ•œ ํ›„, ํ•ต์‹ฌ๊ธฐ๋Šฅ ํด๋ž˜์Šค์˜ ๋ฉ”์†Œ๋“œ(SampleServiceV2 ์˜ sample())๋ฅผ ํ˜ธ์ถœํ•˜๊ฒŒ ๋จ  
= ํ•ต์‹ฌ๊ธฐ๋Šฅ ํด๋ž˜์Šค์˜ ๋ฉ”์†Œ๋“œ(SampleServiceV2 ์˜ sample()) ์‹คํ–‰์‹œ์  ๊ธฐ์ค€์œผ๋กœ ํ”„๋ก์‹œ(SampleServiceV2ProcxyImpl ์˜ sample())๋ฅผ ์ ์šฉํ• ์ˆ˜์žˆ๋‹ค๋Š”๊ฑธ ์•Œ์ˆ˜์žˆ์Œ

๋”ฐ๋ผ์„œ ํ•ต์‹ฌ๊ธฐ๋Šฅ ํด๋ž˜์Šค์˜ ๋ฉ”์†Œ๋“œ(SampleServiceV2 sample()) ๋‚ด์˜ ๋‹ค๋ฅธ ๋ฉ”์†Œ๋“œ๋“ค(SampleServiceV2 ์˜ sampleRecall1(), sampleRecall2())์€ ํ”„๋ก์‹œ์˜ ์˜ํ–ฅ์„ ๋ฐ›์ง€ ์•Š๊ฒŒ ๋จ!

๋ฐ˜์‘ํ˜•

'๊ฐœ๋ฐœ > spring' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

[WebSocket] ์›น์†Œ์ผ“  (0) 2022.03.29
ํŠธ๋žœ์žญ์…˜  (0) 2021.11.25
Spring - ์Šคํ”„๋ง MVC ๊ฐ„๋‹จ ์ •๋ฆฌ  (0) 2021.06.05
Spring - DI (Dependency Injection)  (0) 2021.06.01
Spring - AOP(Aspect-Oriented Programming)  (0) 2021.05.25
๋ฐ˜์‘ํ˜•
WebSocket
์„ค๋ช…

TCP ์ ‘์†์— ์ „์ด์ค‘ ํ†ต์‹  ์ฑ„๋„์„ ์ œ๊ณตํ•˜๋Š” ์ปดํ“จํ„ฐ ํ†ต์‹  ํ”„๋กœํ† ์ฝœ
HTTP ํด๋ง๊ณผ ๊ฐ™์€ ๋ฐ˜์ด์ค‘ ๋ฐฉ์‹์— ๋น„ํ•ด ๋” ๋‚ฎ์€ ๋ถ€ํ•˜๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์›น ๋ธŒ๋ผ์šฐ์ €์™€ ์›น ์„œ๋ฒ„๊ฐ„์˜ ํ†ต์‹ ์„ ๊ฐ€๋Šฅํ•˜๊ฒŒ ํ•จ. 
์„œ๋ฒ„๊ฐ€ ๋‚ด์šฉ์„ ํด๋ผ์ด์–ธํŠธ์— ๋ณด๋‚ด๋Š” ํ‘œ์ค€ํ™”๋œ ๋ฐฉ์‹์„ ์ œ๊ณต
์—ฐ๊ฒฐ์ด ์œ ์ง€๋œ ์ƒํƒœ์—์„œ ๋ฉ”์„ธ์ง€๋“ค์„ ์˜ค๊ฐˆ ์ˆ˜ ์žˆ๊ฒŒ ํ—ˆ์šฉํ•จ. (์–‘๋ฐฉํ–ฅ)

โ€ป ์ „์ด์ค‘ ํ†ต์‹  (Full Duplex)
๋‘ ์ง€์ (์‹œ์ž‘๊ณผ ๋) ์‚ฌ์ด์—์„œ ์ •๋ณด๋ฅผ ์ฃผ๊ณ ๋ฐ›๋Š” ์ „์ž ํ†ต์‹  ์‹œ์Šคํ…œ
โ€ป TCP (Transmission Control Protocol), ์ „์†ก์ œ์–ดํ”„๋กœํ† ์ฝœ
์„œ๋ฒ„๋ผ๋ฆฌ ํ†ต์‹ ์„ ํ•˜๊ธฐ ์œ„ํ•œ ๊ทœ์•ฝ(ํ”„๋กœํ† ์ฝœ)
์›น๋ธŒ๋ผ์šฐ์ €๋“ค์ด WWW์— ์„œ๋ฒ„ ์—ฐ๊ฒฐํ• ๋•Œ ์‚ฌ์šฉ
์ด๋ฉ”์ผ ์ „์†ก ๋ฐ ํŒŒ์ผ ์ „์†ก์‹œ ์‚ฌ์šฉ

โœฑ ์ตœ์ดˆ ์—ฐ๊ฒฐ์‹œ  
    1. ํด๋ผ์ด์–ธํŠธ๊ฐ€ ์„œ๋ฒ„์— ์›น์†Œ์ผ“ ํ•ธ๋“œ์…ฐ์ดํฌ ์š”์ฒญ์„ ๋ณด๋ƒ„
    2. ์„œ๋ฒ„๋Š” ์›น์†Œ์ผ“ ํ•ธ๋“œ์…ฐ์ดํฌ ์‘๋‹ต์„ ๋ณด๋ƒ„
    3. ์ดํ›„๋กœ ํด๋ผ์ด์–ธํŠธ๋Š” ์š”์ฒญ์— ๋Œ€ํ•œ ์‘๋‹ต์„ ๊ธฐ๋‹ค๋ฆฌ์ง€ ์•Š๊ณ  ์š”์ฒญ์„ ๋ณด๋‚ผ์ˆ˜ ์žˆ์Œ. (!= HTTP)


 

Websocket in Spring
๊ด€๋ จ ์˜ˆ์ œ 

https://spring.io/guides/gs/messaging-stomp-websocket/ ์„ ์ฐธ๊ณ ํ•˜์—ฌ ์‹ค์Šต์„ ํ•ด ๋ณด์•˜๋‹ค. 
ํ•ด๋‹น ๋งํฌ๋Š” STOMP(Simple Text Messaging protocol)์„ ์‚ฌ์šฉํ•˜์˜€๋‹ค.

โ€ป STOMP(Simple Text Messaging protocol)
ํ…์ŠคํŠธ ๊ธฐ๋ฐ˜ ๋ฉ”์„ธ์ง• ํ”„๋กœํ† ์ฝœ
์ด๋ฅผ ์ด์šฉํ•˜์—ฌ Binary, Text๊ฐ€ ์•„๋‹Œ ๊ทœ๊ฒฉ์„ ๋งž์ถ˜ ๋ฉ”์„ธ์ง€๋ฅผ ๋ณด๋‚ผ ์ˆ˜ ์žˆ๋‹ค. 
๋ฐœํ–‰(pub), ๊ตฌ๋…(sub), ๋ฉ”์„ธ์ง€๋ธŒ๋กœ์ปค(=๋ฐœ์‹ ์ž๊ฐ€ ๋ฉ”์„ธ์ง€ ๋ฐ›์•„์™€ ์ˆ˜์‹ ์ž์—๊ฒŒ ์ „๋‹ฌ) ๋“ฑ์˜ ๊ฐœ๋…์ด ์žˆ๋‹ค.

๊ฐ„๋‹จํ•œ ์„œ๋ฒ„ ๊ตฌ๋™์‹œ, ์›น์†Œ์ผ“ ๋ฉ”์„ธ์ง• ๋ธŒ๋กœ์ปค๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๊ฒŒ ๋˜๋Š”๋“ฏ ํ•˜๋‹ค. (SimpleBrokerMessageHandler)

+ Fallback Options์œผ๋กœ SockJS์„ ์‚ฌ์šฉํ•˜์˜€๋‹ค. 

 

ํ…Œ์ŠคํŠธ ํ™”๋ฉด

์ตœ์ดˆ์—ฐ๊ฒฐ์‹œ (๋ธŒ๋ผ์šฐ์ €1(์ƒ๋‹จ), ๋ธŒ๋ผ์šฐ์ €2(ํ•˜๋‹จ))

 

๋ธŒ๋ผ์šฐ์ €1์ด TARGET1์„ ์ž…๋ ฅ ํ•˜์˜€์„๋•Œ

๋ธŒ๋ผ์šฐ์ €์—์„œ Send ๋ฒ„ํŠผ ํด๋ฆญ ์‹œ, /app/hello ์„ ํ˜ธ์ถœํ•˜๊ณ 
๋ฉ”์„ธ์ง€ ๋ธŒ๋กœ์ปค ํ•ธ๋“ค๋Ÿฌ ๋‚ด์—์„œ ์ฒ˜๋ฆฌ ํ›„ /topic/greetings ์œผ๋กœ ๊ฒฐ๊ณผ์ •๋ณด๋ฅผ ๋ฐ˜ํ™˜ํ•จ!

 

๋ธŒ๋ผ์šฐ์ €2๊ฐ€ TARGET2์„ ์ž…๋ ฅ ํ•˜์˜€์„๋•Œ

 

 

 


์ฐธ๊ณ 

๋งํฌ: https://ko.wikipedia.org/wiki/%EC%9D%B4%EC%A4%91%ED%86%B5%EC%8B%A0

 

์ด์ค‘ํ†ต์‹  - ์œ„ํ‚ค๋ฐฑ๊ณผ, ์šฐ๋ฆฌ ๋ชจ๋‘์˜ ๋ฐฑ๊ณผ์‚ฌ์ „

์ด์ค‘ํ†ต์‹ (duplex) ๋˜๋Š” ์Œ๋ฐฉํ–ฅ ํ†ต์‹ ์€ ๋‘ ์ง€์  ์‚ฌ์ด์—์„œ ์ •๋ณด๋ฅผ ์ฃผ๊ณ  ๋ฐ›๋Š” ์ „์ž ํ†ต์‹  ์‹œ์Šคํ…œ์„ ๋งํ•œ๋‹ค. ์ด์ค‘ ํ†ต์‹ ์„ ํ•  ๋•Œ ์ „์†ก ๋ฐฉํ–ฅ๋งˆ๋‹ค ๋‘ ๊ฐœ์˜ ํ†ต์‹  ์„ ํ˜ธ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๋‹จ์ˆœํ•˜์ง€๋งŒ ์ „์†ก๋กœ๋ฅผ ์•„๋ผ

ko.wikipedia.org

๋งํฌ: https://ko.wikipedia.org/wiki/%EC%9B%B9%EC%86%8C%EC%BC%93

 

์›น์†Œ์ผ“ - ์œ„ํ‚ค๋ฐฑ๊ณผ, ์šฐ๋ฆฌ ๋ชจ๋‘์˜ ๋ฐฑ๊ณผ์‚ฌ์ „

์›น์†Œ์ผ“(WebSocket)์€ ํ•˜๋‚˜์˜ TCP ์ ‘์†์— ์ „์ด์ค‘ ํ†ต์‹  ์ฑ„๋„์„ ์ œ๊ณตํ•˜๋Š” ์ปดํ“จํ„ฐ ํ†ต์‹  ํ”„๋กœํ† ์ฝœ์ด๋‹ค. ์›น์†Œ์ผ“ ํ”„๋กœํ† ์ฝœ์€ 2011๋…„ IETF์— ์˜ํ•ด RFC 6455๋กœ ํ‘œ์ค€ํ™”๋˜์—ˆ์œผ๋ฉฐ ์›น IDL์˜ ์›น์†Œ์ผ“ API๋Š” W3C์— ์˜ํ•ด ํ‘œ์ค€

ko.wikipedia.org

๋งํฌ :https://ko.wikipedia.org/wiki/%EC%A0%84%EC%86%A1_%EC%A0%9C%EC%96%B4_%ED%94%84%EB%A1%9C%ED%86%A0%EC%BD%9C

 

์ „์†ก ์ œ์–ด ํ”„๋กœํ† ์ฝœ - ์œ„ํ‚ค๋ฐฑ๊ณผ, ์šฐ๋ฆฌ ๋ชจ๋‘์˜ ๋ฐฑ๊ณผ์‚ฌ์ „

์ „์†ก ์ œ์–ด ํ”„๋กœํ† ์ฝœ(Transmission Control Protocol, TCP, ๋ฌธํ™”์–ด: ์ „์†ก์กฐ์ข…๊ทœ์•ฝ)์€ ์ธํ„ฐ๋„ท ํ”„๋กœํ† ์ฝœ ์Šค์œ„ํŠธ(IP)์˜ ํ•ต์‹ฌ ํ”„๋กœํ† ์ฝœ ์ค‘ ํ•˜๋‚˜๋กœ, IP์™€ ํ•จ๊ป˜ TCP/IP๋ผ๋Š” ๋ช…์นญ์œผ๋กœ๋„ ๋„๋ฆฌ ๋ถˆ๋ฆฐ๋‹ค. TCP๋Š” ๊ทผ๊ฑฐ๋ฆฌ ํ†ต์‹ 

ko.wikipedia.org

๋งํฌ: https://namu.wiki/w/TCP

๋งํฌ: https://tecoble.techcourse.co.kr/post/2021-09-05-web-socket-practice/

 

์›น ์†Œ์ผ“์— ๋Œ€ํ•ด ์•Œ์•„๋ณด์ž! - ์‹ค์ „ ํŽธ

์›น ์†Œ์ผ“์— ๋Œ€ํ•ด ์•Œ์•„๋ณด์ž! - ์‹ค์ „ ํŽธ ์ด๋ฒˆ ๊ธ€์—์„œ๋Š” ์ €๋ฒˆ์— ์ž‘์„ฑํ–ˆ๋˜ ์›น ์†Œ์ผ“ ์ด๋ก  ํŽธ์— ์ด์–ด์„œ, ์Šคํ”„๋ง ํ™˜๊ฒฝ์—์„œ ์›น ์†Œ์ผ“์„ ์‚ฌ์šฉํ•˜๋Š” ๋ฒ•์— ๋Œ€ํ•ด ๋‹ค๋ฃจ๋ ค๊ณ  ํ•œ๋‹ค. STOMP ๊ตฌํ˜„ํ•˜๊ธฐ์— ์•ž์„œ, ์šฐ๋ฆฌ๋Š” ์ƒˆ

tecoble.techcourse.co.kr

๋งํฌ: https://tech.kakao.com/2020/06/22/websocket-part3/

 

์‹ค์‹œ๊ฐ„ ๋Œ“๊ธ€ ๊ฐœ๋ฐœ๊ธฐ(part.3) - Spring์˜ ๋™์‹œ์„ฑ ์ ‘๊ทผ ์ œ์–ด์— ๋ฐœ๋ชฉ ์žกํžŒ ์ด์•ผ๊ธฐ

์ „ํŽธ(์‹ค์‹œ๊ฐ„ ๋Œ“๊ธ€ ๊ฐœ๋ฐœ๊ธฐ(part.2) – ํ—˜๋‚œํ–ˆ์ง€๋งŒ ์œ ์ตํ–ˆ๋˜ ์›น์†Œ์ผ“ ์ŠคํŠธ๋ ˆ์Šค ํ…Œ์ŠคํŠธ ๋ฐ ์•ˆ์ •ํ™” ์ž‘์—…)์—์„œ ๊ณต์œ  ๋“œ๋ฆฐ ๋ฐ”์™€ ๊ฐ™์ด ๋‹ค์–‘ํ•œ ๋ชจ๋‹ˆํ„ฐ๋ง ๋ฐ ๋””๋ฒ„๊น… ํˆด์˜ ์‹ค์ œ ํ™œ์šฉ ์‚ฌ๋ก€์ธ Spring SimpleBroker ํŠœ

tech.kakao.com

๋งํฌ: https://www.youtube.com/watch?v=rvss-_t6gzg

 

๋ฐ˜์‘ํ˜•

'๊ฐœ๋ฐœ > spring' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

[AOP] AOP ์ ์šฉ ๊ด€๋ จ ์ด์Šˆ  (0) 2024.05.14
ํŠธ๋žœ์žญ์…˜  (0) 2021.11.25
Spring - ์Šคํ”„๋ง MVC ๊ฐ„๋‹จ ์ •๋ฆฌ  (0) 2021.06.05
Spring - DI (Dependency Injection)  (0) 2021.06.01
Spring - AOP(Aspect-Oriented Programming)  (0) 2021.05.25
๋ฐ˜์‘ํ˜•
ํŠธ๋žœ์žญ์…˜
์„ค๋ช…

๋‘๊ฐœ ์ด์ƒ์˜ ์ฟผ๋ฆฌ๋ฅผ ํ•œ ์ž‘์—…์œผ๋กœ ์‹คํ–‰ํ•ด์•ผ ํ•  ๋•Œ ์‚ฌ์šฉํ•˜๋Š”๊ฒƒ 
ํŠธ๋žœ์žญ์…˜์œผ๋กœ ๋ฌถ์ธ ์ฟผ๋ฆฌ ์ค‘ ํ•˜๋‚˜๋ผ๋„ ์‹คํŒจํ•˜๋ฉด ์ „์ฒด ์‹คํŒจ๋กœ ๊ฐ„์ฃผ -> ๊ธฐ์กด์ƒํƒœ๋กœ ๋˜๋Œ๋ฆผ (rollback)
ํŠธ๋žœ์žญ์…˜์œผ๋กœ ๋ฌถ์ธ ์ฟผ๋ฆฌ๊ฐ€ ๋ชจ๋‘ ์„ฑ๊ณตํ•  ๊ฒฝ์šฐ -> ์‹ค์ œ๋ฐ˜์˜ (commit)

 

@Transactional
์„ค๋ช…

์Šคํ”„๋ง์—์„œ ํŠธ๋žœ์žญ์…˜ ๋ฒ”์œ„๋ฅผ ์„ค์ •ํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•˜๋Š” ์–ด๋…ธํ…Œ์ด์…˜ 
ํŠธ๋žœ์žญ์…˜ ๋ฒ”์œ„๋ฅผ ์„ค์ •ํ•˜๊ณ  ์‹ถ์„๋•Œ ์‚ฌ์šฉํ•จ.
์ œ๋Œ€๋กœ๋œ ๋™์ž‘์„ ํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” PlatformTransactionManager ๋นˆ ์„ค์ • & @Transactional ์–ด๋…ธํ…Œ์ด์…˜ ํ™œ์„ฑํ™” ์„ค์ • ์ด ํ•„์š”

PlatformTransactionManager
- ํŠธ๋žœ์žญ์…˜ ์ฒ˜๋ฆฌ์— ํ•„์š”ํ•œ API ์ œ๊ณต
- ๊ฐœ๋ฐœ์ž๊ฐ€ API๋ฅผ ํ˜ธ์ถœํ•˜๋Š” ๊ฒƒ์œผ๋กœ ํŠธ๋žœ์žญ์…˜ ์กฐ์ž‘์„ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ๋‹ค.
- ๋Œ€ํ‘œ์ ์ธ ๊ตฌํ˜„ ํด๋ž˜์Šค: DataSourceTransactionManager, HibernateTransactionManager, JpaTransactionManager, JtaTransactionManager, WebLogicJtaTransactionManager, WebSphereUowTransactionManager
@Transactional ์–ด๋…ธํ…Œ์ด์…˜ ํ™œ์„ฑํ™” ์„ค์ •
 - @EnableTransactionManagement ์–ด๋…ธํ…Œ์ด์…˜์„ ์ด์šฉํ•˜์—ฌ @Transactional ์–ด๋…ธํ…Œ์ด์…˜์ด ๋ถ™์€ ๋ฉ”์„œ๋“œ๋ฅผ ํŠธ๋žœ์žญ์…˜ ๋ฒ”์œ„์—์„œ ์‹คํ–‰ํ•˜๋Š” ๊ธฐ๋Šฅ์„ ํ™œ์„ฑํ™”
- ๋“ฑ๋ก๋œ PlatformTransactionManager ๋นˆ์„ ์‚ฌ์šฉํ•ด์„œ ํŠธ๋žœ์žญ์…˜์„ ์ ์šฉํ•œ๋‹ค.

 

@Transactional๊ณผ ํ”„๋ก์‹œ

์Šคํ”„๋ง์€ ํŠธ๋žœ์žญ์…˜์„ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด ๋‚ด๋ถ€์ ์œผ๋กœ AOP์„ ์ด์šฉํ•จ!

 

..

 

 

ํŠธ๋žœ์žญ์…˜ ๊ด€๋ฆฌ์ž ์ •์˜

๋กœ์ปฌํŠธ๋žœ์žญ์…˜์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ JDBC API ํ˜ธ์ถœ, ํŠธ๋žœ์žญ์…˜ ์ œ์–ด๋ฅผ ์ˆ˜ํ–‰ํ•˜๋Š” DataSourceTransactionManager์„ ์‚ฌ์šฉํ•œ๋‹ค.
๋‹จ์ผ ๋ฐ์ดํ„ฐ ์ €์žฅ์†Œ์— ๋Œ€ํ•œ ์—ฌ๋Ÿฌ ์กฐ์ž‘์„ ํ•˜๋‚˜์˜ ๋…ผ๋ฆฌ์  ๋‹จ์œ„๋กœ ์ฒ˜๋ฆฌํ•˜๊ณ  ์‹ถ์„๋•Œ ์‚ฌ์šฉ

๊ธ€๋กœ๋ฒŒํŠธ๋žœ์žญ์…˜์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ(์—ฌ๋Ÿฌ ๋ฐ์ดํ„ฐ ์ €์žฅ์†Œ์— ๊ฑธ์ณ์„œ ์ ์šฉ๋˜๋Š” ๊ฒฝ์šฐ: DB๊ฐ€ ์—ฌ๋Ÿฌ๊ฐœ์ด๊ณ , ๊ฐ๊ฐ ์กฐ์ž‘ ์ˆ˜ํ–‰ ๋‹จ์œ„๋ฅผ ํ•˜๋‚˜์˜ ํŠธ๋ž˜์žญ์…˜์œผ๋กœ ๋ฌถ๋Š” ๊ฒฝ์šฐ) JtaTransactionManager ์„ ์‚ฌ์šฉ

 

 

์„ ์–ธ์  ํŠธ๋žœ์žญ์…˜ 
์„ค๋ช…

commit, rollback ๋“ฑ์˜ ์ฒ˜๋ฆฌ๋ฅผ ๋น„์ง€๋‹ˆ์Šค ๋กœ์ง์— ์„œ์ˆ ํ•˜์ง€ ์•Š๊ณ  ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ• (@Transactional)

ํ•„์š”์ •๋ณด

value
transactionManager
propagation
isolation
timeout
readOnly
rollbackFor
rollbackForClassName
noRollbackFor
noRollbackForClassName

.....

 

๋ช…์‹œ์  ํŠธ๋žœ์žญ์…˜
์„ค๋ช…

์ปค๋ฐ‹์ด๋‚˜ ๋กค๋ฐฑ๊ณผ ๊ฐ™์€ ํŠธ๋žœ์žญ์…˜ ์ฒ˜๋ฆฌ๋ฅผ ์†Œ์Šค์ฝ”๋“œ์— ์ง์ ‘ ๋ช…์‹œํ•˜๋Š” ๋ฐฉ๋ฒ•.
๋ฉ”์„œ๋“œ ๋‹จ์œ„๋ณด๋‹ค ๋” ์ž‘์€ ๋‹จ์œ„๋กœ ํŠธ๋žœ์žญ์…˜์„ ์ œ์–ดํ•˜๊ณ  ์‹ถ์„๋•Œ ์‚ฌ์šฉ.
PlatformTransactionManager, TransactionTemplate์„ ์‚ฌ์šฉํ•˜๋Š” ๋‘๊ฐ€์ง€ ๋ฐฉ๋ฒ• ์ œ๊ณต

....

 

ํŠธ๋žœ์žญ์…˜ ๊ฒฉ๋ฆฌ์ˆ˜์ค€
์„ค๋ช…

๋™์‹œ์— DB์— ์ ‘๊ทผํ•  ๋•Œ ๊ทธ ์ ‘๊ทผ์„ ์–ด๋–ป๊ฒŒ ์ œ์–ดํ• ์ง€์— ๋Œ€ํ•œ ์„ค์ •์„ ๋‹ค๋ฃธ.
DEFAULT, READ_UNCOMMITTED, READ_COMMITTED, REPEATABLE_READ, SERIALIZABLE
....

 

 

 

 


์ฐธ๊ณ 

(์ฑ…) ์ดˆ๋ณด ์›น ๊ฐœ๋ฐœ์ž๋ฅผ ์œ„ํ•œ ์Šคํ”„๋ง5 ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์ž…๋ฌธ
(์ฑ…) ์Šคํ”„๋ง ์ฒ ์ € ์ž…๋ฌธ 

๋ฐ˜์‘ํ˜•
๋ฐ˜์‘ํ˜•

์–ด๋””์„œ ๋งŽ์ด ๋ณธ ๊ทธ๋ฆผ

 

 

filter
์„ค๋ช…

dispatcherServlet ํ˜ธ์ถœ ์ „, ์š”์ฒญ์— ๋Œ€ํ•ด์„œ ์ „์ฒ˜๋ฆฌ ์ž‘์—…(์›ํ•˜๋Š” ํ˜•ํƒœ๋กœ ๋ณ€ํ˜•)์ด ํ•„์š”ํ•œ ๊ฒฝ์šฐ ์‚ฌ์šฉํ•˜๋Š”๊ฒƒ. (์›น ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์—์„œ ๋“ฑ๋ก)
filter chain ์„ ํ†ตํ•ด ์—ฐ์‡„์ ์œผ๋กœ ๋™์ž‘ํ•  ์ˆ˜ ์žˆ๊ฒŒ ๊ฐ€๋Šฅ.
์ธ์ฆ, ๊ถŒํ•œ, CORS, ์ธ์ฝ”๋”ฉ, XSS ์ž‘์—…์‹œ ์ด์šฉ

 

 

dispatcherServlet
์„ค๋ช…

ํ”„๋ŸฐํŠธ ์ปจํŠธ๋กค๋Ÿฌ์™€ ์—ฐ๋™๋˜๋Š” ์ง„์ž…์  ์—ญํ• ์„ ํ•˜๋ฉฐ, ๊ธฐ๋ณธ์ ์ธ ์ฒ˜๋ฆฌ ํ๋ฆ„์„ ์ œ์–ดํ•˜๋Š” ์‚ฌ๋ นํƒ‘ ์—ญํ• ์„ ํ•œ๋‹ค. 

โœฟ ํ”„๋ก ํŠธ ์ปจํŠธ๋กค๋Ÿฌ?
ํด๋ผ์ด์–ธํŠธ ์š”์ฒญ์„ ํ”„๋ŸฐํŠธ ์ปจํŠธ๋กค๋Ÿฌ๋ผ๋Š” ์ปดํฌ๋„ŒํŠธ๊ฐ€ ๋ฐ›์•„ ์š”์ฒญ ๋‚ด์šฉ์— ๋”ฐ๋ผ ์ˆ˜ํ–‰ํ•˜๋Š” ํ•ธ๋“ค๋Ÿฌ(Handler)๋ฅผ ์„ ํƒํ•˜๋Š” ์•„ํ‚คํ…์ฒ˜

 

dispatcherServlet๊ณผ ์—ฐ๋™๋˜๋Š” ์ธํ„ฐํŽ˜์ด์Šค
์ธํ„ฐํŽ˜์ด์Šค๋ช… ์—ญํ• 
HandlerExceptionResolver ์˜ˆ์™ธ์ฒ˜๋ฆฌ ์ธํ„ฐํŽ˜์ด์Šค.
LocaleResolver
LocaleContextResolver
ํด๋ผ์ด์–ธํŠธ Locale ์ •๋ณด๋ฅผ ํ™•์ธํ•˜๊ธฐ ์œ„ํ•œ ์ธํ„ฐํŽ˜์ด์Šค.
ThemeResolver ์Šคํ”„๋ง ํ…Œ๋งˆ๋ฅผ ๊ฒฐ์ •ํ•˜๊ธฐ ์œ„ํ•œ ์ธํ„ฐํŽ˜์ด์Šค.
FlashMapManager FlashMap์ด๋ผ๋Š” ๊ฐ์ฒด๋ฅผ ๊ด€๋ฆฌํ•˜๊ธฐ ์œ„ํ•œ ์ธํ„ฐํŽ˜์ด์Šค.
RequestToViewNameTranslator ํ•ธ๋“ค๋Ÿฌ๊ฐ€ ๋ทฐ ์ด๋ฆ„๊ณผ ๋ทฐ๋ฅผ ๋ฐ˜ํ™˜ํ•˜์ง€ ์•Š๋Š” ๊ฒฝ์šฐ ์ ์šฉ๋˜๋Š” ๋ทฐ ์ด๋ฆ„์„ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•œ ์ธํ„ฐํŽ˜์ด์Šค. ์Šคํ”„๋ง MVC์—์„œ ์ œ๊ณตํ•˜๋Š” ๊ธฐ๋ณธ ๊ตฌํ˜„ ํด๋ž˜์Šค๊ฐ€ ์ ์šฉ๋˜์–ด ์žˆ๋‹ค.
HandlerInterceptor ํ•ธ๋“ค๋Ÿฌ ์‹คํ–‰ ์ „ํ›„์— ํ•˜๋Š” ๊ณตํ†ต ์ฒ˜๋ฆฌ๋ฅผ ๊ตฌํ˜„ํ•˜๊ธฐ ์œ„ํ•œ ์ธํ„ฐํŽ˜์ด์Šค. ์ด ์ธํ„ฐํŽ˜์ด์Šค๋Š” ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ฐœ๋ฐœ์ž๊ฐ€ ๊ตฌํ˜„ํ•˜๊ณ  ์Šคํ”„๋ง MVC์— ๋“ฑ๋กํ•˜์—ฌ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.
MultipartResolver ๋ฉ€ํ‹ฐํŒŒํŠธ ์š”์ฒญ์„ ์ฒ˜๋ฆฌํ•˜๊ธฐ ์œ„ํ•œ ์ธํ„ฐํŽ˜์ด์Šค. ์Šคํ”„๋ง MVC์—์„œ ๋ช‡ ๊ฐ€์ง€ ๊ตฌํ˜„ ํด๋ž˜์Šค๊ฐ€ ์ œ๊ณต๋˜๊ณ  ์žˆ์ง€๋งŒ ๊ธฐ๋ณธ์ ์œผ๋กœ ์ ์šฉ๋˜์ง€ ์•Š๋Š”๋‹ค.

 

 

Handler
์„ค๋ช…

ํ”„๋ ˆ์ž„์›Œํฌ ๊ด€์ ์—์„œ ๋ถˆ๋ฆฌ๋Š” Handler๋Š” ๊ฐœ๋ฐœ์ž๊ฐ€ ์ž‘์„ฑํ•˜๋Š” ํด๋ž˜์Šค์˜ ๊ด€์ ์—์„œ Controller ์ด๋‹ค.

 

 

HandlerMapping
์„ค๋ช…

์š”์ฒญ์— ๋Œ€์‘ํ•  ํ•ธ๋“ค๋Ÿฌ๋ฅผ ์„ ํƒํ•˜๋Š” ์—ญํ• ์„ ์ˆ˜ํ–‰ํ•œ๋‹ค. (์ปจํŠธ๋กค๋Ÿฌ๋‚ด์˜ ๋ฉ”์†Œ๋“œ๊ฐ€ ํ•ธ๋“ค๋Ÿฌ๋กœ ์ธ์‹!)
ํด๋ผ์ด์–ธํŠธ(๋ธŒ๋ผ์šฐ์ €)์—์„œ ์š”์ฒญ์ด ์˜ฌ ๊ฒฝ์šฐ RequestMappingHandlerMapping ํด๋ž˜์Šค๋Š”
์š”์ฒญ ๋‚ด์šฉ(์š”์ฒญ ๊ฒฝ๋กœ ํ˜น์€ HTTP ๋ฉ”์„œ๋“œ)๊ณผ ์š”์ฒญ ๋งคํ•‘ ์ •๋ณด๋ฅผ ๋งค์นญํ•ด์„œ ์‹คํ–‰ํ•  ํ•ธ๋“ค๋Ÿฌ๋ฅด ์„ ํƒํ•œ๋‹ค!

@Controller
class TestController {
    @RequestMapping("/hello")
    public String hello() {
        return "/hi";
    }
    // hello ๋ฉ”์†Œ๋“œ๊ฐ€ ํ•ธ๋“ค๋Ÿฌ!
}

 

 

HandlerAdapter
์„ค๋ช…

ํ•ธ๋“ค๋Ÿฌ ๋ฉ”์„œ๋“œ๋ฅผ ํ˜ธ์ถœํ•˜๋Š” ์—ญํ• ์„ ํ•œ๋‹ค. (RequestMappingHandlerAdapter)
RequestMappingHandlerAdapter ํด๋ž˜์Šค ์—์„œ๋Š” ํ•ธ๋“ค๋Ÿฌ ๋ฉ”์„œ๋“œ์— ๋งค๊ฐœ๋ณ€์ˆ˜๋ฅผ ์ „๋‹ฌํ•˜๊ณ  ๋ฉ”์„œ๋“œ์˜ ์ฒ˜๋ฆฌ ๊ฒฐ๊ณผ๋ฅผ ๋ฐ˜ํ™˜๊ฐ’์œผ๋กœ ๋˜๋Œ๋ ค ๋ณด๋ƒ„
๋นˆ ๊ฐ์ฒด ๊ฒ€์‚ฌ ๋“ฑ๋“ฑ์„ ํ•จ.

 

 

ViewResolver
์„ค๋ช…

ํ•ธ๋“ค๋Ÿฌ์—์„œ ๋ฐ˜ํ™˜ํ•œ ๋ทฐ ์ด๋ฆ„์„ ๋ณด๊ณ , ์ดํ›„์— ์‚ฌ์šฉํ•  View ์ธํ„ฐํŽ˜์ด์Šค์˜ ๊ตฌํ˜„ ํด๋ž˜์Šค๋ฅผ ์„ ํƒํ•˜๋Š” ์—ญํ• ์„ ํ•œ๋‹ค.

 


์ฐธ๊ณ 

(์ฑ…) ์Šคํ”„๋ง ์ฒ ์ € ์ž…๋ฌธ
(์ฑ…) ์Šคํ”„๋ง ๋ถ€ํŠธ๋กœ ๋ฐฐ์šฐ๋Š” ์ž๋ฐ” ์›น ๊ฐœ๋ฐœ
https://exhibitlove.tistory.com/7

 

[springboot] Filter ์„ค์ •

์ถœ์ฒ˜ : https://linked2ev.github.io/gitlog/2019/09/15/springboot-mvc-13-%EC%8A%A4%ED%94%84%EB%A7%81%EB%B6%80%ED%8A%B8-MVC-Filter-%EC%84%A4%EC%A0%95/ Filter๋ž€? ํ•„ํ„ฐ๋ž€? ๊ฑฐ๋ฅธ๋‹ค๋Š” ๋œป์ด๋‹ค. ์„œ๋ธ”๋ฆฟ์˜ Servl..

exhibitlove.tistory.com

https://stargatex.wordpress.com/2015/12/08/spring-mvc-request-lifecycle/

๋ฐ˜์‘ํ˜•

'๊ฐœ๋ฐœ > spring' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

[WebSocket] ์›น์†Œ์ผ“  (0) 2022.03.29
ํŠธ๋žœ์žญ์…˜  (0) 2021.11.25
Spring - DI (Dependency Injection)  (0) 2021.06.01
Spring - AOP(Aspect-Oriented Programming)  (0) 2021.05.25
IOC/DI, DI์‘์šฉ  (0) 2017.11.20
๋ฐ˜์‘ํ˜•
DI
์„ค๋ช…

์˜์กด์„ฑ ์ฃผ์ž…์ด๋ผ๊ณ ๋„ ํ•˜๋ฉฐ, IoC (Inversion of Control) ๋ผ๊ณ  ํ•˜๋Š” ์†Œํ”„ํŠธ์›จ์–ด ๋””์ž์ธ ํŒจํ„ด ์ค‘ ํ•˜๋‚˜.
์–ด๋–ค ํด๋ž˜์Šค๊ฐ€ ํ•„์š”๋กœ ํ•˜๋Š” ์ปดํฌ๋„ŒํŠธ๋ฅผ ์™ธ๋ถ€์—์„œ ์ƒ์„ฑํ•œ ํ›„, ๋‚ด๋ถ€์—์„œ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•˜๊ฒŒ ๋งŒ๋“ค์–ด ์ฃผ๋Š” ๊ณผ์ •

DI ์ปจํ…Œ์ด๋„ˆ๋ฅผ ํ†ตํ•ด ๊ฐ ์ปดํฌ๋„ŒํŠธ์˜ ์ธ์Šคํ„ด์Šค๋ฅผ ์ƒ์„ฑํ•˜๊ณ  ํ†ตํ•ฉ ๊ด€๋ฆฌํ•˜๋ฉด์„œ ์ปดํฌ๋„ŒํŠธ๊ฐ„ ์˜์กด์„ฑ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ๋‹ค.

โœณ๏ธŽ ๋นˆ (@bean)
spring DI container์— ์˜ํ•ด ๊ด€๋ฆฌ๋˜๋Š” ๊ฐ์ฒด 
ApplicationContext.getBean(XXX.class) ์œผ๋กœ ์–ป์–ด์ง€๋Š” ๊ฐ์ฒด๋ฅผ ์˜๋ฏธ


โœณ๏ธŽ ์ปดํฌ๋„ŒํŠธ (@Component)
์‚ฌ์šฉ์ž๊ฐ€ ๋งŒ๋“  bean ์„ ์ž๋™์œผ๋กœ ๊ฐ์ง€ํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•œ ๊ฒƒ


โœณ๏ธŽ IoC ์ปจํ…Œ์ด๋„ˆ (Inversion of Control)
์˜์กด์„ฑ ์ฃผ์ž…์„ ์ž๋™์œผ๋กœ ์ฒ˜๋ฆฌํ•˜๋Š” ๊ธฐ๋ฐ˜์ด๊ณ  ์ธ์Šคํ„ด์Šค ๊ตฌ์„ฑ ๋ฐ ๋นˆ ์กฐ๋ฆฝ์„ ๋‹ด๋‹นํ•œ๋‹ค.
๋นˆ ํŒฉํ† ๋ฆฌ(Bean Factory)๋ผ๊ณ ๋„ ํ•จ.
Bean Factory์— ์—ฌ๋Ÿฌ๊ฐ€์ง€ ์ปจํ…Œ์ด๋„ˆ ๊ธฐ๋Šฅ์„ ์ถ”๊ฐ€ํ•˜์—ฌ ApplicationContext๋ผ๊ณ  ๋ถ€๋ฆ„. (Bean Factory์˜ ํ™•์žฅ)


โœณ๏ธŽ Bean Factory
Bean ์„ ๋“ฑ๋ก/์ƒ์„ฑ/์กฐํ™”/๋ฐ˜ํ™˜ ๊ด€๋ฆฌํ•จ.


โœณ๏ธŽ ApplicationContext
spring bean์„ ๋ณด์œ ํ•˜๊ณ ์žˆ๋Š”๊ณณ
Bean Factory ์™€ ๊ธฐ๋Šฅ ๊ฐ™๊ณ , Spring์˜ ๋ถ€๊ฐ€ ์„œ๋น„์Šค๋ฅผ ์ถ”๊ฐ€๋กœ ์ œ๊ณต


์–ด๋–ค ์ปดํฌ๋„ŒํŠธ๋Š” ์‹ฑ๊ธ€ํ„ด(singleton) ๊ฐ์ฒด๋กœ ๋งŒ๋“ค์–ด์•ผ ํ•˜๋ฉฐ, ์–ด๋–ค ์ปดํฌ๋„ŒํŠธ๋Š” ํ”„๋กœํ† ํƒ€์ž…(prototype) ๊ฐ์ฒด๋กœ ๋งŒ๋“ค์–ด์•ผ ํ•œ๋‹ค. ์ด๋Ÿฌํ•œ ์ธ์Šคํ„ด์Šค ์Šค์ฝ”ํ”„(scope) ๊ด€๋ฆฌ๋ฅผ DI ์ปจํ…Œ์ด๋„ˆ๊ฐ€ ๋Œ€์‹  ํ•ด์ค€๋‹ค.

 

DI ๋ฐฉ๋ฒ• 3๊ฐ€์ง€

1. ์„ค์ •์ž ๊ธฐ๋ฐ˜ (setter-based)
  setter method ์— @Autowired ์„ ์ ์šฉ

@RestController
public class AController {
    private A a;

    @Autowired
    public void setA(A a) {
	    this.a = a;
    }
}


2. ์ƒ์„ฑ์ž ๊ธฐ๋ฐ˜ (contructor-based)
  ์ƒ์„ฑ์ž ์ธ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•ด ์˜์กด์„ฑ์„ ์ฃผ์ž…ํ•˜๋Š” ๋ฐฉ์‹

@RestController
public class AController {
    private final A a;
    
    public AController(A a){
        this.a = a;
    }
}

 

3. ํ•„๋“œ๊ธฐ๋ฐ˜ (field-based)
  ์‚ฌ์šฉํ•˜๊ณ  ์‹ถ์€ ํ•„๋“œ์— @Autowired ์„ ์ ์šฉ 

@RestController
public class AController {
    
    @Autowired
    private A a;
}

 

โœณ๏ธŽ @Autowired
๋นˆ์„ ์ž๋™์œผ๋กœ ์ฃผ์ž…ํ•˜๋Š” ๋ฐฉ์‹

 

ํ•„๋“œ ๊ธฐ๋ฐ˜ ๋ฐฉ์‹์€ ์ถ”์ฒœํ•˜์ง€ ์•Š๋Š”๋‹ค. (์ƒ์„ฑ์ž ๋ฐฉ์‹์œผ๋กœ ์‚ฌ์šฉํ•˜๋Š”๊ฒƒ์„ ๊ถŒ์žฅ)
์ถ”์ฒœํ•˜์ง€ ์•Š๋Š” ์ด์œ ๋Š” ์ˆœํ™˜์ฐธ์กฐ ๋•Œ๋ฌธ! 

โœณ๏ธŽ ์ˆœํ™˜์ฐธ์กฐ
์„œ๋กœ ๋‹ค๋ฅธ ํด๋ž˜์Šค๊ฐ€ ์„œ๋กœ๋ฅผ ์ฐธ์กฐํ•˜๊ณ  ์žˆ๋Š” ์ƒํƒœ, ๋”ฐ๋ผ์„œ ์Šคํ”„๋ง ์ปจํ…Œ์ด๋„ˆ๊ฐ€ ์–ด๋–ค ๋นˆ์„ ๋จผ์ € ์ƒ์„ฑํ•ด์•ผํ• ์ง€ ํŒ๋‹จ์„ ํ•˜์ง€ ๋ชปํ•ด์„œ ๋ฐœ์ƒํ•˜๋Š” ๋ฌธ์ œ!

์ƒ์„ฑ์ž ๋ฐฉ์‹์„ ์ถ”์ฒœํ•˜๋Š” ์ด์œ ๋Š” ํ…Œ์ŠคํŠธ ์ฝ”๋“œ ์ž‘์„ฑ์— ์šฉ์˜ํ•˜๋ฉฐ, ์‹คํ–‰ ์ค‘ ๊ฐ์ฒด๊ฐ€ ๋ณ€๊ฒฝ๋˜๋Š” ๊ฒƒ์„ ๋ฐฉ์ง€ํ•  ์ˆ˜ ์žˆ๋‹ค.
  

 

DI ์ปจํ…Œ์ด๋„ˆ ์‚ฌ์šฉ์˜ ์žฅ์ 
์žฅ์ 

  ์ธ์Šคํ„ด์Šค ์Šค์ฝ”ํ”„ ์ œ์–ด
  ์ธ์Šคํ„ด์Šค ์ƒ๋ช…์ฃผ๊ธฐ ์ œ์–ด
  AOP ๋ฐฉ์‹์œผ๋กœ ๊ณตํ†ต๊ธฐ๋Šฅ ์ ์šฉ ๊ฐ€๋Šฅ
  ์˜์กดํ•˜๋Š” ์ปดํฌ๋„ŒํŠธ ๊ฐ„์˜ ๊ฒฐํ•ฉ๋„๋ฅผ ๋‚ฎ์ถฐ ๋‹จ์œ„ํ…Œ์ŠคํŠธ ์‰ฝ๊ฒŒ ๊ฐ€๋Šฅ

 

 

๋นˆ ์„ค์ • ๋ฐฉ๋ฒ•
์„ค์ • ๋ฐฉ๋ฒ• 3๊ฐ€์ง€

1. ์ž๋ฐ” ๊ธฐ๋ฐ˜ ์„ค์ • ๋ฐฉ์‹ (Java-based configuration)
  - ์ž๋ฐ” ํด๋ž˜์Šค์— @Configuration, ๋ฉ”์†Œ๋“œ์— @Bean ์„ ์‚ฌ์šฉํ•ด ๋นˆ์„ ์ •์˜ํ•˜๋Š” ๋ฐฉ๋ฒ•

2. XML ๊ธฐ๋ฐ˜ ์„ค์ • ๋ฐ˜์‹ (XML-based configuration)
  - XML ํŒŒ์ผ์„ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ• (<bean>, <constructor-arg>, <property>)

3. ์• ๋„ˆํ…Œ์ด์…˜ ๊ธฐ๋ฐ˜ ์„ค์ • ๋ฐฉ์‹ (Annotation-based configuration)
  - @Component ๊ฐ™์€ ๋งˆ์ปค ์–ด๋…ธํ…Œ์ด์…˜์ด ๋ถ€์—ฌ๋œ ํด๋ž˜์Šค๋ฅผ ํƒ์ƒ‰ํ•ด์„œ(Component Scan) IoC์ปจํ…Œ์ด๋„ˆ์— ๋นˆ์„ ์ž๋™์œผ๋กœ ๋“ฑ๋กํ•˜๋Š” ๋ฐฉ๋ฒ•.

 

 

์ปดํฌ๋„ŒํŠธ ์Šค์บ” (Component Scan)
์„ค๋ช…

ํด๋ž˜์Šค ๋กœ๋”(Class Loader)๋ฅผ ์Šค์บ”ํ•˜๋ฉด์„œ ํŠน์ • ํด๋ž˜์Šค๋ฅผ ์ฐพ์€ ๋‹ค์Œ, DI ์ปจํ…Œ์ด๋„ˆ์— ๋“ฑ๋กํ•˜๋Š” ๋ฐฉ๋ฒ•

 

์ข…๋ฅ˜

@Component, @Controller, @Service, @Repository, @Configuration, @RestController, @ControllerAdvice, @ManagedBean, @Named ..

 

 


์ฐธ๊ณ 

(์ฑ…) ์Šคํ”„๋ง ์ฒ ์ € ์ž…๋ฌธ
http://blog.naver.com/PostView.nhn?blogId=gngh0101&logNo=221179100057&parentCategoryNo=&categoryNo=32&viewDate=&isShowPopularPosts=false&from=postView
https://dog-developers.tistory.com/12
https://ict-nroo.tistory.com/120
https://www.baeldung.com/spring-component-annotation
https://docs.spring.io/spring-framework/docs/current/reference/html/core.html#beans-basics

๋ฐ˜์‘ํ˜•

'๊ฐœ๋ฐœ > spring' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

ํŠธ๋žœ์žญ์…˜  (0) 2021.11.25
Spring - ์Šคํ”„๋ง MVC ๊ฐ„๋‹จ ์ •๋ฆฌ  (0) 2021.06.05
Spring - AOP(Aspect-Oriented Programming)  (0) 2021.05.25
IOC/DI, DI์‘์šฉ  (0) 2017.11.20
spring ์‹œ์ž‘, maven ์„ค์น˜  (0) 2017.11.12
๋ฐ˜์‘ํ˜•
AOP (Aspect-Oriented Programming)
์„ค๋ช…

์—ฌ๋Ÿฌ ๋กœ์ง๋‹จ์— ์ ์šฉ๋˜์–ด์•ผ ํ•  ํŠน์ • ์ค‘๋ณต ๋กœ์ง์„ ์—ฌ๋Ÿฌ ์ฝ”๋“œ๋ฅผ ์ˆ˜์ •ํ•˜์ง€ ์•Š๊ณ  ์ ์šฉํ•˜๋Š” ๊ฒƒ
ํฉ์–ด์ง„ ์ฝ”๋“œ๋ฅผ ํ•œ๊ณณ์œผ๋กœ ๋ชจ์œผ์ž!
ํšก๋‹จ ๊ด€์‹ฌ์— ๋”ฐ๋ผ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ํ•˜๋Š”๊ฒƒ

โ€ป ํšก๋‹จ
๋™์„œ ๋ฐฉํ–ฅ์œผ๋กœ ๊ฐ€๋กœ์งˆ๋Ÿฌ ๊ฐ€๋Š”๊ฒƒ
โ€ป ํšก๋‹จ ๊ด€์‹ฌ์‚ฌ (Cross cutting concern)

๋‹ค์ˆ˜์˜ ๋ชจ๋“ˆ์— ๊ณตํ†ต์ ์œผ๋กœ ๋‚˜ํƒ€๋‚˜๋Š” ๋ถ€๋ถ„์ด ์กด์žฌ
๋ชจ๋“ˆ๋ณ„๋กœ ๋ฐ˜๋ณต๋˜์–ด ์ค‘๋ณตํ•ด์„œ ๋‚˜ํƒ€๋‚˜๋Š” ๋ถ€๋ถ„๋ฐ˜๋ณต๊ณผ ์ค‘๋ณต์€ ๋ถ„๋ฆฌํ•˜์—ฌ ํ•œ๊ณณ์—์„œ ํ‘œํ˜„ํ•ด์•ผ ํ•œ๋‹ค๋ผ๋Š”๊ฒƒ์„ ํ•ญ์ƒ ์ธ์ง€ํ•ด์•ผ ํ•จ.
ํŠน์ง•

Aspect ์œผ๋กœ ํ‘œํ˜„
๋กœ์ง(Code) ์ฃผ์ž…
๋กœ๊น…, ๋ณด์•ˆ, ํŠธ๋žœ์žญ์…˜ ๊ธฐ๋Šฅ์ด ๋ฐ˜๋ณต์ ์œผ๋กœ ๋‚˜ํƒ€๋‚จ
AOP๋Š” ํ”„๋ก์‹œ ๊ธฐ๋ฐ˜, ์ธํ„ฐํŽ˜์ด์Šค ๊ธฐ๋ฐ˜, ๋Ÿฐํƒ€์ž„ ๊ธฐ๋ฐ˜ ์ด๋‹ค.

 

๋ฉ”์†Œ๋“œ์— ์ฃผ์ž…ํ•  ์ˆ˜ ์žˆ๋Š” ์˜์—ญ

@Before: ๋Œ€์ƒ ๋ฉ”์†Œ๋“œ ์‹œ์ž‘ ์ „
@After: ๋Œ€์ƒ ๋ฉ”์†Œ๋“œ ์‹œ์ž‘ ํ›„
    @AfterReturning: ๋Œ€์ƒ ๋ฉ”์†Œ๋“œ ์ •์ƒ ์ข…๋ฃŒ ํ›„ 
    @AfterThrowing: ๋Œ€์ƒ ๋ฉ”์†Œ๋“œ ์˜ˆ์™ธ ๋ฐœ์ƒ → ์ข…๋ฃŒ ํ›„

 

AOP ์šฉ์–ด
Aspect ์—ฌ๋Ÿฌ๊ฐœ์˜ Advice, ์—ฌ๋Ÿฌ๊ฐœ์˜ Pointcut์˜ ๊ฒฐํ•ฉ์ฒด๋ฅผ ์˜๋ฏธํ•˜๋Š” ์šฉ์–ด
Advisor ํ•œ๊ฐœ์˜ Advice, ํ•œ๊ฐœ์˜ Pointcut
Advice pointcut์— ์ ์šฉํ•  ๋กœ์ง, ์ฆ‰ ๋ฉ”์„œ๋“œ๋ฅผ ์˜๋ฏธ 

@Before("execution( * runSomething())") 
public void before(JoinPoint joinPoint) { ... }
JoinPoint ์—ฐ๊ฒฐ์ . ์—ฐ๊ฒฐ ๊ฐ€๋Šฅํ•œ ์ง€์ . Aspect ์ ์šฉ ๊ฐ€๋Šฅ ์ง€์ . ์Šคํ”„๋ง ํ”„๋ ˆ์ž„์›Œํฌ๊ฐ€ ๊ด€๋ฆฌํ•˜๋Š” ๋นˆ์˜ ๋ชจ๋“  ๋ฉ”์„œ๋“œ

public void before(JoinPoint joinPoint) { ... }
Pointcut ์ž๋ฅด๋Š” ์ง€์ , Aspect ์ ์šฉ ์œ„์น˜ ์ง€์ •์ž. ํšก๋‹จ ๊ด€์‹ฌ์‚ฌ๋ฅผ ์ ์šฉํ•  ํƒ€๊นƒ ๋ฉ”์„œ๋“œ๋ฅผ ์„ ํƒํ•˜๋Š” ์ง€์‹œ์ž.

@Before("execution( * runSomething())") → runSomething() ์‹คํ–‰ ์ „ AOP์„ ์‹คํ–‰ํ•˜๋ผ๋Š” ๋œป

 

Pointcut ์ง€์ •์ž ๊ด€๋ จ

 
  execution

์ผ์น˜ํ•˜๋Š” ๋ฉ”์„œ๋“œ ์‹คํ–‰ ์กฐ์ธ ํฌ์ธํŠธ์— ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค. ์ด๊ฒƒ์€ Spring AOP๋กœ ์ž‘์—… ํ•  ๋•Œ ์‚ฌ์šฉํ•˜๋Š” ์ฃผ์š” ํฌ์ธํŠธ ์ปท ์ง€์ •์ž์ž…๋‹ˆ๋‹ค.

  within
ํŠน์ • ์œ ํ˜• ๋‚ด ๊ฒฐํ•ฉ ์ ์— ๋Œ€ํ•œ ๋งค์นญ์„ ์ œํ•œํ•ฉ๋‹ˆ๋‹ค (Spring AOP ์‚ฌ์šฉ์‹œ ๋งค์นญ ์œ ํ˜• ๋‚ด์—์„œ ์„ ์–ธ ๋œ ๋ฉ”์†Œ๋“œ ์‹คํ–‰).

  this
๋นˆ ์ฐธ์กฐ (Spring AOP ํ”„๋ก์‹œ)๊ฐ€ ์ฃผ์–ด์ง„ ์œ ํ˜•์˜ ์ธ์Šคํ„ด์Šค ์ธ ์กฐ์ธ ํฌ์ธํŠธ (Spring AOP ์‚ฌ์šฉ์‹œ ๋ฉ”์†Œ๋“œ ์‹คํ–‰)์— ๋Œ€ํ•œ ๋งค์นญ์„ ์ œํ•œํ•ฉ๋‹ˆ๋‹ค.

  target
๋Œ€์ƒ ๊ฐ์ฒด (ํ”„๋ก์‹œ๋˜๋Š” ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ฐ์ฒด)๊ฐ€ ์ฃผ์–ด์ง„ ์œ ํ˜•์˜ ์ธ์Šคํ„ด์Šค ์ธ ์กฐ์ธ ํฌ์ธํŠธ (Spring AOP ์‚ฌ์šฉ์‹œ ๋ฉ”์„œ๋“œ ์‹คํ–‰)์— ๋Œ€ํ•œ ๋งค์นญ์„ ์ œํ•œํ•ฉ๋‹ˆ๋‹ค.

  args
์ธ์ˆ˜๊ฐ€ ์ฃผ์–ด์ง„ ์œ ํ˜•์˜ ์ธ์Šคํ„ด์Šค ์ธ ์กฐ์ธ ํฌ์ธํŠธ (Spring AOP ์‚ฌ์šฉ์‹œ ๋ฉ”์„œ๋“œ ์‹คํ–‰)์— ๋Œ€ํ•œ ๋งค์นญ์„ ์ œํ•œํ•ฉ๋‹ˆ๋‹ค.

  @target
์‹คํ–‰ ๊ฐ์ฒด์˜ ํด๋ž˜์Šค๊ฐ€ ์ฃผ์–ด์ง„ ํƒ€์ž…์˜ ์–ด๋…ธํ…Œ์ด์…˜์„ ๊ฐ€์ง€๊ณ ์žˆ๋Š” join point (Spring AOP ์‚ฌ์šฉ์‹œ ๋ฉ”์†Œ๋“œ ์‹คํ–‰)๋กœ ๋งค์นญ์„ ์ œํ•œํ•ฉ๋‹ˆ๋‹ค.

  @args
์ „๋‹ฌ ๋œ ์‹ค์ œ ์ธ์ˆ˜์˜ ๋Ÿฐํƒ€์ž„ ์œ ํ˜•์ด ์ฃผ์–ด์ง„ ์œ ํ˜•์˜ ์–ด๋…ธํ…Œ์ด์…˜์„ ๊ฐ–๋Š” ๊ฒฐํ•ฉ ์ง€์  (Spring AOP ์‚ฌ์šฉ์‹œ ๋ฉ”์†Œ๋“œ ์‹คํ–‰)์— ๋Œ€ํ•œ ์ผ์น˜๋ฅผ ์ œํ•œํ•ฉ๋‹ˆ๋‹ค.

  @within
์ฃผ์–ด์ง„ ์–ด๋…ธํ…Œ์ด์…˜ (Spring AOP๋ฅผ ์‚ฌ์šฉํ•  ๋•Œ ์ฃผ์–ด์ง„ ์–ด๋…ธํ…Œ์ด์…˜์ด์žˆ๋Š” ํƒ€์ž…์—์„œ ์„ ์–ธ ๋œ ๋ฉ”์†Œ๋“œ์˜ ์‹คํ–‰)์ด์žˆ๋Š” ํƒ€์ž… ๋‚ด์—์„œ ์กฐ์ธ ํฌ์ธํŠธ์— ๋Œ€ํ•œ ๋งค์นญ์„ ์ œํ•œํ•ฉ๋‹ˆ๋‹ค.

  @annotation
Join point์˜ ์ฃผ์ œ (Spring AOP์—์„œ ์‹คํ–‰๋˜๋Š” ๋ฉ”์†Œ๋“œ)๊ฐ€ ์ฃผ์–ด์ง„ ์–ด๋…ธํ…Œ์ด์…˜์„ ๊ฐ€์ง€๊ณ ์žˆ๋Š” join point๋กœ ๋งค์นญ์„ ์ œํ•œํ•ฉ๋‹ˆ๋‹ค.

 

Pointcut ํ‘œํ˜„์‹ ์˜ˆ์ œ

 
  ๋ชจ๋“  ๊ณต์šฉ ๋ฉ”์†Œ๋“œ ์‹คํ–‰

execution(public * * (..))

  ๋‹ค์Œ์œผ๋กœ ์‹œ์ž‘ํ•˜๋Š” ์ด๋ฆ„์„ ๊ฐ€์ง„ ๋ชจ๋“  ๋ฉ”์†Œ๋“œ์˜ ์‹คํ–‰ 
setexecution(* set * (..))

  AccountService์ธํ„ฐํŽ˜์ด์Šค์— ์˜ํ•ด ์ •์˜ ๋œ ๋ชจ๋“  ๋ฉ”์†Œ๋“œ์˜ ์‹คํ–‰ 
execution(* com.xyz.service.AccountService. * (..))

  serviceํŒจํ‚ค์ง€์— ์ •์˜ ๋œ ๋ชจ๋“  ๋ฉ”์†Œ๋“œ ์‹คํ–‰ 
execution(* com.xyz.service. *. * (..))

  ์„œ๋น„์Šค ํŒจํ‚ค์ง€ ๋˜๋Š” ํ•˜์œ„ ํŒจํ‚ค์ง€ ์ค‘ ํ•˜๋‚˜์— ์ •์˜ ๋œ ๋ชจ๋“  ๋ฉ”์„œ๋“œ ์‹คํ–‰
execution(* com.xyz.service .. *. * (..))

  ์„œ๋น„์Šค ํŒจํ‚ค์ง€ ๋‚ด์˜ ๋ชจ๋“  ์กฐ์ธ ํฌ์ธํŠธ (Spring AOP์—์„œ๋งŒ ๋ฉ”์„œ๋“œ ์‹คํ–‰)
within(com.xyz.service. *)

 ์„œ๋น„์Šค ํŒจํ‚ค์ง€ ๋˜๋Š” ํ•˜์œ„ ํŒจํ‚ค์ง€ ์ค‘ ํ•˜๋‚˜ ๋‚ด์˜ ๋ชจ๋“  ์กฐ์ธ ์ง€์  (Spring AOP์—์„œ๋งŒ ๋ฉ”์„œ๋“œ ์‹คํ–‰)
within(com.xyz.service .. *)

  ํ”„๋ก์‹œ๊ฐ€ AccountService์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ๊ตฌํ˜„ํ•˜๋Š” ๋ชจ๋“  ์กฐ์ธ ํฌ์ธํŠธ (Spring AOP์—์„œ๋งŒ ๋ฉ”์„œ๋“œ ์‹คํ–‰) 
this(com.xyz.service.AccountService)

 


 

์ฐธ๊ณ 


https://wikibook.co.kr/java-oop-for-spring/ (์ฑ…: ์Šคํ”„๋ง ์ž…๋ฌธ์„ ์œ„ํ•œ ์ž๋ฐ” ๊ฐ์ฒด์ง€ํ–ฅ์˜ ์›๋ฆฌ์™€ ์ดํ•ด)
https://docs.spring.io/spring-framework/docs/current/reference/html/core.html#aop

 

๋ฐ˜์‘ํ˜•

'๊ฐœ๋ฐœ > spring' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

ํŠธ๋žœ์žญ์…˜  (0) 2021.11.25
Spring - ์Šคํ”„๋ง MVC ๊ฐ„๋‹จ ์ •๋ฆฌ  (0) 2021.06.05
Spring - DI (Dependency Injection)  (0) 2021.06.01
IOC/DI, DI์‘์šฉ  (0) 2017.11.20
spring ์‹œ์ž‘, maven ์„ค์น˜  (0) 2017.11.12
๋ฐ˜์‘ํ˜•

์Šคํ”„๋ง์€ ์ž๋ฐ”์ฝ”๋“œ๊ฐ€ ์ง์ ‘ ์ฒ˜๋ฆฌํ•˜์ง€์•Š๊ณ  ์ปจํ…Œ์ด๋„ˆ(ex. xmlํŒŒ์ผ ์ฃผ์ž…)๊ฐ€ ๋Œ€์‹  ์ฒ˜๋ฆฌ๋ฅผ ํ•ด์คŒ. ---> IOC ๊ฐœ๋… (์ œ์–ด์˜ ์—ญ์ „, ๋‚ฎ์€ ๊ฒฐํ•ฉ๋„)


์™ธ๋ถ€์—์žˆ๋Š” ๊ฐ์ฒด๋ฅผ ํ˜„์žฌ๊ฐ์ฒด์— ์ฃผ์ž…ํ•˜์—ฌ ๊ฒฐ๊ณผ๋ฅผ ๋„์ถœ ---> DI(์˜์กด์„ฑ์ฃผ์ž…) ๊ฐœ๋…

์ฆ‰,


(setter ์ฃผ์ž… ๋ฐฉ์‹)

 AAA a = new AAA();
BBB b = new BBB(a); -- DI


(xml ์ฃผ์ž… ๋ฐฉ์‹ : ์ƒ์„ฑ์ž ํ˜น์€ ํ”„๋กœํผํ‹ฐ)

xml์— ํด๋ž˜์Šค ์ƒ์„ฑ์ž๋‚˜ ํ”„๋กœํผํ‹ฐ ๊ฐ’์„ ์ฃผ์ž…ํ•˜์—ฌ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ์‹์ธ๋“ฏ (?)

๋ฌธ๋ฒ•์€ ์•„๋ž˜์— ๋‚˜์™€์žˆ์Œ 


+ ์ถ”๊ฐ€, (IOC/DI ๊ฒฐ๋ก )

๋‘ ๊ฐœ์˜ ์˜ค๋ธŒ์ ํŠธ๋ฅผ ๋ถ„๋ฆฌํ•ด์„œ ๋งŒ๋“ค๊ณ , ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ๋‘๊ณ  ๋Š์Šจํ•˜๊ฒŒ ์—ฐ๊ฒฐํ•œ ๋’ค, ์‹ค์ œ ์‚ฌ์šฉํ•  ๋Œ€์ƒ์€ DI๋ฅผ ํ†ตํ•ด ์™ธ๋ถ€์—์„œ ์ง€์ •
์ถœ์ฒ˜: http://jinpyo900.tistory.com/55 [Computer Science ]



[1] ์˜ˆ์ œ


๋‚˜์ž์‹ ์ด ์ดํ•ดํ•˜๊ธฐ ์œ„ํ•ด ์˜ˆ์ œ๋ฅผ ๋งŒ๋“ค์–ด๋ด„.

DI_test.zip



zip ํŒŒ์ผ์— ๋Œ€ํ•œ ๋‚ด์šฉ์€ ๋‹ค์Œ๊ณผ ๊ฐ™์€๋ฐ...๋ญ ๊ทธ๋Ÿฌํ•จ

๋‚ด๊ฐ€ ์ดํ•ดํ•œ๊ฑด ์ด์ •๋„...??



Main ํด๋ž˜์Šค์—์„œ...

String configLocation = "classpath:context_calc.xml"; //xml ๋ถˆ๋Ÿฌ์˜ด
AbstractApplicationContext ctx = new GenericXmlApplicationContext(configLocation);
CalcData calcdata = ctx.getBean("calcdata", CalcData.class); //xml์—์„œ beans id๊ฐ€ calcdata๊ฐ€๋จ
calcdata.resultfunc(); //ํ˜ธ์ถœํ•˜๋Š” ๋ฉ”์†Œ๋“œ(๊ฒฐ๊ณผ)
ctx.close();//๋



[2] xml ์ด์šฉํ•œ DI์„ค์ •

1) bean : ์Šคํ”„๋ง ์ปจํ…Œ์ด๋„ˆ๊ฐ€ ์ƒ์„ฑํ•  ๊ฐ์ฒด์— ๋Œ€ํ•œ ์ •๋ณด ์ง€์ •์‹œ ์‚ฌ์šฉ

<bean id="์—ฐ๊ฒฐํ• ์ด๋ฆ„" class="ํŒจํ‚ค์ง€๋ช….ํด๋ž˜์Šค๋ช…"></bean>


2) constructor-org : ์ƒ์„ฑ์ž ํŒŒ๋ผ๋ฏธํ„ฐ ์„ค์ •์‹œ ์‚ฌ์šฉ

<bean id="์—ฐ๊ฒฐํ• ์ด๋ฆ„" class="ํŒจํ‚ค์ง€๋ช….ํด๋ž˜์Šค๋ช…">
 <constructor-org value="aaa"/> // ---> new A("aaa"); ์ด๋ ‡๊ฒŒ๋จ
</bean>


3) property : ํ•ด๋‹น ๋นˆ์ฆˆ ํด๋ž˜์Šค๋‚ด์— setํ•  ๋ณ€์ˆ˜, ํด๋ž˜์Šค๋“ฑ๋“ฑ์„ ์…‹ํŒ…ํ•ด์คŒ

<bean id="์—ฐ๊ฒฐํ• ์ด๋ฆ„" class="ํŒจํ‚ค์ง€๋ช….ํด๋ž˜์Šค๋ช…">
 <property name="๋ณ€์ˆ˜๋ช…" value="1"/>
 <property name="๋ณ€์ˆ˜๋ช…">
   <ref bean="๋ถˆ๋Ÿฌ์˜จํด๋ž˜์Šค๋ช…๋ณ€์ˆ˜"/>
 </property>
</bean>
<bean id="๋ถˆ๋Ÿฌ์˜จํด๋ž˜์Šค๋ช…๋ณ€์ˆ˜" class="ํŒจํ‚ค์ง€๋ช….๋ถˆ๋Ÿฌ์˜จํด๋ž˜์Šค๋ช…๋ณ€์ˆ˜">
</bean>


 - list

 - map

 - set

 - value

 - ref


4) c ๋„ค์ž„์ŠคํŽ˜์ด์Šค, p๋„ค์ž„์ŠคํŽ˜์ด์Šค : C๋Š” construct-org, p๋Š” property ๋„ค์ž„ ์ŠคํŽ˜์ด์Šค

<bean id="์—ฐ๊ฒฐํ• ์ด๋ฆ„" class="ํŒจํ‚ค์ง€๋ช….ํด๋ž˜์Šค๋ช…" c:id="dsfd" p:id="fsdfs"/>
5) import : ๋‹ค๋ฅธ xml ๋ถˆ๋Ÿฌ์˜ฌ๋•Œ...



[3] Java ์ฝ”๋“œ๋ฅผ ์ด์šฉํ•˜์—ฌ DI์„ค์ • (์–ด๋…ธํ…Œ์ด์…˜์ด์šฉ)

์ด๋Š” xml์„ค์ •๋Œ€์‹  Java์ฝ”๋“œ๋กœ ์„ค์ •ํ•˜์˜€์„๋•Œ ์•„๋ž˜์™€ ๊ฐ™์€ ํ˜•ํƒœ๋กœ ๋ฉ”์†Œ๋“œ์œ„์— ๋ถ™์—ฌ์„œ ์“ฐ๋‚˜๋ถ€๋‹ค. (@ : ์• ๋…ธํ…Œ์ด์…˜)


1) @Configuration : ํด๋ž˜์Šค๋ฅผ ์Šคํ”„๋ง์„ค์ •์œผ๋กœ ์‚ฌ์šฉํ•จ




์ฐธ๊ณ  : http://asfirstalways.tistory.com/334

๋ฐ˜์‘ํ˜•

'๊ฐœ๋ฐœ > spring' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

ํŠธ๋žœ์žญ์…˜  (0) 2021.11.25
Spring - ์Šคํ”„๋ง MVC ๊ฐ„๋‹จ ์ •๋ฆฌ  (0) 2021.06.05
Spring - DI (Dependency Injection)  (0) 2021.06.01
Spring - AOP(Aspect-Oriented Programming)  (0) 2021.05.25
spring ์‹œ์ž‘, maven ์„ค์น˜  (0) 2017.11.12
๋ฐ˜์‘ํ˜•


[1] ์„ค์น˜๋ชฉ๋ก : ์ž๋ฐ”, ํ†ฐ์บฃ, maven, ์ดํด๋ฆฝ์Šค...DB..


1) ์ž๋ฐ”์„ค์น˜

  ๋ณด์•„ํ•˜๋‹ˆ 1.9 ๋ฒ„์ „๊นŒ์ง€ ๋‚˜์˜จ๊ฑฐ๊ฐ™์€๋ฐ ๋‚˜๋Š” 1.8 ๋ฒ„์ „ ์•„๋ฌด๊ฑฐ๋‚˜ ์„ค์น˜ํ•จ.

  http://www.oracle.com/technetwork/java/javase/downloads/index.html


  ์„ค์น˜ํ•˜๋Š”๋ฒ•์€ ๋งŽ์ด ๋‚˜์˜ค๋‹ˆ ์•Œ์•„์„œ ์„ค์น˜ํ•˜๊ณ , 

  ํ™˜๊ฒฝ๋ณ€์ˆ˜ ์…‹ํŒ… ๊ผญ ํ•˜๋„๋ก(maven ์„ค์น˜ํ•˜๊ณ  ์ง์ ‘ ํ”„๋กœ์ ํŠธ ๋งŒ๋“ค๋•Œ ํ•ด๋ด์•ผํ•˜๋‹ˆ..)

  ์ œ์–ดํŒ\์‹œ์Šคํ…œ ๋ฐ ๋ณด์•ˆ\์‹œ์Šคํ…œ\๊ณ ๊ธ‰์‹œ์Šคํ…œ์„ค์ •\ํ™˜๊ฒฝ๋ณ€์ˆ˜ 

   --> ์‹œ์Šคํ…œ๋ณ€์ˆ˜์— JAVA_HOME ๋ณ€์ˆ˜ ์ถ”๊ฐ€ (์ด๋ฆ„์„ JAVA_HOME, ๊ฒฝ๋กœ๋ฅผ ์ž๋ฐ”jdk์œ„์น˜ ๊นŒ์ง€ ex) c:\~~~\java~~~\jdk~~~)

   --> ์‹œ์Šคํ…œ๋ณ€์ˆ˜์ค‘ path๋ผ๋Š” ๋ณ€์ˆ˜ ํŽธ์ง‘๋ฒ„ํŠผ ํด๋ฆญํ•˜์—ฌ JAVA_HOME ์ถ”๊ฐ€ (ex. ๋ธ”๋ผ๋ธ”๋ผ~~;%JAVA_HOME%\bin)

   --> cmd ๋“ค์–ด๊ฐ€์„œ javac ์ณ๋ณด๊ณ  ์ด์ƒํ•˜๋ฉด java ์ง€์šฐ๊ณ  ๋‹ค์‹œ ์„ค์น˜ํ•ด๋ณด๋„๋ก....


2) ํ†ฐ์บฃ์„ค์น˜(์›น์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์„œ๋ฒ„)

  ์–ด์Œ ๋‚˜๋Š” tomcat 7์„ ์„ค์น˜ํ•จ... ๊ฒ€์ƒ‰ํ•˜๋ฉด ์„ค์น˜ํ•˜๋Š”๋ฒ• ๋งŽ์ด๋‚˜์˜ด. ๋‹ค์šด๋ฐ›๊ณ  ์›ํ•˜๋Š” ํด๋”์— ๋„ฃ์Œ.

  https://tomcat.apache.org/download-70.cgi 


  โ€ป ์ฐธ๊ณ  : ํ†ฐ์บฃ ๋ฒ„์ „๋ณ„ ์„œ๋ธ”๋ฆฟ ์ŠคํŽ™

  http://zetawiki.com/wiki/%ED%86%B0%EC%BA%A3_%EB%B2%84%EC%A0%84%EB%B3%84_%EC%84%9C%EB%B8%94%EB%A6%BF_%EC%8A%A4%ED%8E%99

ํ†ฐ์บฃ ๋ฒ„์ „Servlet ์ŠคํŽ™JSP ์ŠคํŽ™์›น์†Œ์ผ“ ์ŠคํŽ™์ตœ์†Œ Java ๋ฒ„์ „
9.04.02.4(์˜ˆ์ •)1.2(์˜ˆ์ •)8
8.03.12.31.17
7.03.02.21.16
6.02.52.1-5
5.52.42.0-1.4
4.12.31.2-1.3
3.32.21.1-1.1

  โ€ป ์•„ํŒŒ์น˜๋Š” ์›น์„œ๋ฒ„, ํ†ฐ์บฃ์€ ์›น์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜ ์„œ๋ฒ„(์›น์„œ๋ฒ„ ํฌํ•จ)

  http://gap85.tistory.com/45



3) maven ์„ค์น˜

  ๋ฉ”์ด๋ธ์ด.... ์Šคํ”„๋งํ”„๋ ˆ์ž„์›Œํฌ์“ธ๋•Œ ํŽธ๋ฆฌํ•˜๊ฒŒ ํด๋” ๊ด€๋ฆฌํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•ด์ฃผ๋Š” ๊ทธ๋Ÿฐ ๋ชจ๋“ˆ์ธ๊ฐ€๋ด„

  * ๊ด€๋ จ๋‚ด์šฉ : http://javacan.tistory.com/entry/MavenBasic

  * ๋ฉ”์ด๋ธ ์„ค์น˜ : https://maven.apache.org/download.cgi


4) ์ดํด๋ฆฝ์Šค ์„ค์น˜ ๋ฐ ํ™•์ธ

 https://www.eclipse.org/downloads/download.php?file=/oomph/epp/oxygen/R/eclipse-inst-win64.exe ๊ฐ€์„œ์„ค์น˜..


5) DB

 ๋ญ์Œ....mysql?



[2] ํ”„๋กœ์ ํŠธ ์‹คํ–‰์ „์—..


1) ์ดํด๋ฆฝ์Šค ์„ค์ •

  1.ํ†ฐ์บฃ ์„ค์ • 

    -> window>properties>server>Runtime Environments ๊ฐ€์„œ Add๋ฒ„ํŠผํด๋ฆญ 

    -> ํ•ด๋‹น ํ†ฐ์บฃ๋ฒ„์ „ ํด๋ฆญ ํ›„ next (๋‚˜์˜๊ฒฝ์šฐ๋Š” 7.0) 

    -> Browses ๋ฒ„ํŠผ ํด๋ฆญํ•˜์—ฌ ํ†ฐ์บฃ ํด๋” ์œ„์น˜ ๋“ฑ๋ก. (ํ†ฐ์บฃํด๋”์œ„์น˜) ๋ฐ Finish


  2.์ธ์ฝ”๋”ฉ ์„ค์ •

    -> ๋‚˜์˜๊ฒฝ์šฐ๋Š” UTF-8๋กœ ์„ค์ •...

  

  3.์ดํด๋ฆฝ์Šค ๋‚ด์— ์Šคํ”„๋งํˆด ์„ค์น˜

    -> help>eclips marketplace ํด๋ฆญํ•˜์—ฌ sts ๊ฒ€์ƒ‰ ํ›„ install

    -> ์„ค์น˜๋๋‚˜๋ฉด ์˜ค๋ฅธ์ชฝ ์ƒ๋‹จ +๋ฒ„ํŠผํด๋ฆญํ•˜์—ฌ spring ์ถ”๊ฐ€



[3] Maven ํ”„๋กœ์ ํŠธ ๋งŒ๋“ค๊ธฐ


1) ์ง์ ‘ ๋งŒ๋“ค๊ธฐ

  1. ๋ฉ”์ด๋ธ ์„ค์น˜ํ•  ํด๋” ์ƒ์„ฑํ•˜๊ธฐ (C:\aaa)


  2. cmd๋กœ aaa ํด๋” ์ด๋™ํ•˜์—ฌ mvn archetype:generate ๋ช…๋ น์–ด ์‹คํ–‰. ๊ทธ๋Ÿผ ๋ง‰ ๋‹ค์šด๋ฐ›์•„์ง

     ๋ฌด์Šจ ์ž…๋ ฅํ•˜๋Š”๊ฒŒ ๋‚˜์˜ค๋Š”๋ฐ ๊ณ„์† ์—”ํ„ฐ์น˜๋‹ค๊ฐ€ 

     groupId : ํŒจํ‚ค์ง€root์ž…๋ ฅ(ex. aaa.bbb.ccc), artifactId : ํŒจํ‚ค์ง€ ์ƒ์œ„ ํด๋”๋ช…(ex. A) 

     ์ž…๋ ฅ ํ›„ ์—”ํ„ฐ

     --> ์ด๊ฑฐ ์•ˆ๋˜๋ฉด, java ํ™˜๊ฒฝ๋ณ€์ˆ˜ ์„ค์ • ์ œ๋Œ€๋กœ ์•ˆ๋œ๊ฑด์ง€ ๋“ฑ๋“ฑ ํ™•์ธ ํ•„์š”ํ•จ.

  

  3. ๋‹ค์šด๋ฐ›๊ธฐ ๋๋‚˜๋ฉด src/main ์— resources ํด๋” ์ƒ์„ฑ 

     (ํ›—๋‚  ์Šคํ”„๋ง์—์„œ ํŠน์ • ํ”„๋กœ์ ํŠธ ์ž‘์—…์‹œ์— ์‚ฌ์šฉํ•˜๋Š” xml ํŒŒ์ผ ๋‹ด๋Š” ํด๋”์ธ๋“ฏ....ํด๋ž˜์ŠคํŒจ์Šค์— ์œ„์น˜ํ•ด์•ผํ•  xml...properties...)


  3. pom.xml ์— ๋‚ด์šฉ์ถ”๊ฐ€ (์Šคํ”„๋ง ๋ฒ„์ „ ๋ญ์“ด๋‹ค, ์ธ์ฝ”๋”ฉ ๋ญ์“ด๋‹ค ๋‚ด์šฉ์ถ”๊ฐ€)

  

  4. ์ดํด๋ฆฝ์Šค ๋‚ด์— Import ์ฒ˜๋ฆฌ

     ์ดํด๋ฆฝ์Šค ํ”„๋กœ์ ํŠธ ๋ฆฌ์ŠคํŠธ ํ™”๋ฉด์— ์˜ค๋ฅธ์ชฝ ๋ฒ„ํŠผ ํด๋ฆญํ•˜์—ฌ Import ํ•˜๊ธฐ.

     (Maven/Exsisting Maven Project ํด๋ฆญํ•˜์—ฌ import ์ฒ˜๋ฆฌ, pom.xml ์€ ์ฒดํฌ๊ผญ!)


  5. ์ƒ์„ฑ๋œ ํ”„๋กœ์ ํŠธ ๋‚ด์— JRE System Library ์˜ค๋ฅธ์ชฝ๋ฒ„ํŠผํด๋ฆญ> properties๊ฐ€์„œ java ๋ฒ„์ „ ์„ค์ • ๋‹ค์‹œํ•˜๊ธฐ (๋‚˜์˜๊ฒฝ์šฐ๋Š” 1.8)



2) ์ดํด๋ฆฝ์Šค ๋‚ด์—์„œ ๋งŒ๋“ค๊ธฐ

  1. ์ดํด๋ฆฝ์Šค์—์„œ ํ”„๋กœ์ ํŠธ ๋งŒ๋“ค๋“ฏ์ด ๋งŒ๋“ค๋ฉด๋จ. 

     (๋‚˜์˜๊ฒฝ์šฐ๋Š” legacy project๋กœ ๋งŒ๋“ค์—ˆ๊ณ , ๋งŒ๋“ค๋•Œ groupId, artifactId ์ž…๋ ฅํ•˜๋Š”๊ฒƒ์ด ๋‚˜์˜ฌ๊ฒƒ์ž„)

  

๋ฐ˜์‘ํ˜•

'๊ฐœ๋ฐœ > spring' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

ํŠธ๋žœ์žญ์…˜  (0) 2021.11.25
Spring - ์Šคํ”„๋ง MVC ๊ฐ„๋‹จ ์ •๋ฆฌ  (0) 2021.06.05
Spring - DI (Dependency Injection)  (0) 2021.06.01
Spring - AOP(Aspect-Oriented Programming)  (0) 2021.05.25
IOC/DI, DI์‘์šฉ  (0) 2017.11.20

+ Recent posts