๐Ÿ’ Spring/Spring ํ•ต์‹ฌ ๊ธฐ์ˆ 

๐Ÿ’ Spring/Spring ํ•ต์‹ฌ ๊ธฐ์ˆ 

13. ๋ฐ์ดํ„ฐ ๋ฐ”์ธ๋”ฉ ์ถ”์ƒํ™” : PropertyEditor

org.springframework.validation.DataBinder ๊ธฐ์ˆ ์ ์ธ ๊ด€์  : ํ”„๋กœํผํ‹ฐ ๊ฐ’์„ ํƒ€์ผ“ ๊ฐ์ฒด์— ์„ค์ •ํ•˜๋Š” ๊ธฐ๋Šฅ ์‚ฌ์šฉ์ž ๊ด€์  : ์‚ฌ์šฉ์ž ์ž…๋ ฅ๊ฐ’์„ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋„๋ฉ”์ธ ๋ชจ๋ธ์— ๋™์ ์œผ๋กœ ๋ณ€ํ™˜ํ•ด ๋„ฃ์–ด์ฃผ๋Š” ๊ธฐ๋Šฅ ํ•ด์„ํ•˜๋ฉด : ์ž…๋ ฅ๊ฐ’์€ ๋Œ€๋ถ€๋ถ„ "๋ฌธ์ž์—ด"์ธ๋ฐ, ๊ทธ ๊ฐ’์„ ๊ฐ์ฒด๊ฐ€ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ํ”„๋กœํผํ‹ฐ ํƒ€์ž… (์ฆ‰, int, long, boolean, Date ๋“ฑ๋“ฑ ) ์‹ฌ์ง€์–ด, Event,Book ๊ฐ™์€ ๋„๋ฉ”์ธ ํƒ€์ž…์œผ๋กœ๋„ ๋ณ€ํ™˜ํ•ด์„œ ๋„ฃ์–ด์ฃผ๋Š” ๊ธฐ๋Šฅ. PropertyEditor ์Šคํ”„๋ง 3.0 ์ด์ „๊นŒ์ง€ DataBinder๊ฐ€ ๋ณ€ํ™˜ ์ž‘์—… ์‚ฌ์šฉํ•˜๋˜ ์ธํ„ฐํŽ˜์ด์Šค ์“ฐ๋ ˆ๋“œ - ์„ธ์ดํ”„ ํ•˜์ง€ ์•Š์Œ (์ƒํƒœ ์ •๋ณด ์ €์žฅ ํ•˜๊ณ  ์žˆ์Œ, ๋”ฐ๋ผ์„œ ์‹ฑ๊ธ€ํ†ค ๋นˆ์œผ๋กœ ๋“ฑ๋กํ•ด์„œ ์‚ฌ์šฉํ•˜๋‹ค๊ฐ€๋Š”...) Object์™€ String ๊ฐ„์˜ ๋ณ€ํ™˜๋งŒ ํ•  ์ˆ˜ ์žˆ์–ด,..

๐Ÿ’ Spring/Spring ํ•ต์‹ฌ ๊ธฐ์ˆ 

12. Validation ์ถ”์ƒํ™”

Validation์€ ํฌ๊ฒŒ ๋‘๊ฐ€์ง€๊ฐ€ ์žˆ๋‹ค. JavaBean ๊ธฐ๋ฐ˜ Validation (๊ฐ€์žฅ ๋งŽ์ด ์‚ฌ์šฉ) Spring Validation ์ธํ„ฐํŽ˜์ด์Šค ๊ตฌํ˜„ํ•˜์—ฌ Validation org.springframework.validation.Validatior ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์—์„œ ์‚ฌ์šฉํ•˜๋Š” ๊ฐ์ฒด ๊ฒ€์ฆ์šฉ ์ธํ„ฐํŽ˜์ด์Šค ํŠน์ง• ์–ด๋–ค ๊ณ„์ธต๊ณผ๋„ ๊ด€๊ณ„๊ฐ€ ์—†๋‹ค. -> ๋ชจ๋“  ๊ณ„์ธต(์›น, ์„œ๋น„์Šค, ๋ฐ์ดํ„ฐ) ์—์„œ ์‚ฌ์šฉํ•ด๋„ ์ข‹๋‹ค. ๊ตฌํ˜„์ฒด ์ค‘ ํ•˜๋‚˜๋กœ, JSR-303(Bean Validation 1.0), JSR-349(Bean Validation 1.1) ์„ ์ง€์›ํ•œ๋‹ค.(LocalValidatorFactoryBean) DataBinder์— ๋“ค์–ด๊ฐ€ ๋ฐ”์ธ๋”ฉ ํ•  ๋•Œ ๊ฐ™์ด ์‚ฌ์šฉ๋˜๊ธฐ๋„ ํ•œ๋‹ค. ์ธํ„ฐํŽ˜์ด์Šค : org.springframework.validati..

๐Ÿ’ Spring/Spring ํ•ต์‹ฌ ๊ธฐ์ˆ 

11. Resource ์ถ”์ƒํ™”

org.springframework.core.io.Resource Resource ์ถ”์ƒํ™”๋ž€? springframework.core.io.Resource๋กœ java.net.URL๋ผ๋Š” ํด๋ž˜์Šค๋ฅผ ๊ฐ์‹ธ๊ณ , ์‹ค์ œ low level์— ์žˆ๋Š” Resource์— ์ ‘๊ทผํ•˜๋Š” ๊ธฐ๋Šฅ ์„ ์ถ”์ƒํ™”๋ผ๊ณ  ํ•œ๋‹ค. ํŠน์ง• java.net.URL ์„ ์ถ”์ƒํ™” ํ•œ ๊ฒƒ ์Šคํ”„๋ง ๋‚ด๋ถ€์—์„œ ๋งŽ์ด ์‚ฌ์šฉํ•˜๋Š” ์ธํ„ฐํŽ˜์ด์Šค! ์ถ”์ƒํ™” ํ•œ ์ด์œ  ํด๋ž˜์ŠคํŒจ์Šค ๊ธฐ์ค€์œผ๋กœ ๋ฆฌ์†Œ์Šค ์ฝ์–ด์˜ค๋Š” ๊ธฐ๋Šฅ ๋ถ€์žฌ ServletContext๋ฅผ ๊ธฐ์ค€์œผ๋กœ ์ƒ๋Œ€ ๊ฒฝ๋กœ๋กœ ์ฝ์–ด์˜ค๋Š” ๊ธฐ๋Šฅ ๋ถ€์žฌ ์ƒˆ๋กœ์šด ํ•ธ๋“ค๋Ÿฌ๋ฅผ ๋“ฑ๋กํ•˜์—ฌ ํŠน๋ณ„ํ•œ URL ์ ‘๋ฏธ์‚ฌ๋ฅผ ๋งŒ๋“ค์–ด ์‚ฌ์šฉํ•  ์ˆ˜๋Š” ์žˆ์ง€๋งŒ ๊ตฌํ˜„์ด ๋ณต์žกํ•˜๊ณ  ํŽธ์˜์„ฑ ๋ฉ”์†Œ๋“œ๊ฐ€ ๋ถ€์กฑํ•˜๋‹ค. ์šฐ๋ฆฌ๊ฐ€ ApplicationContext๋ฅผ ๋งŒ๋“ค๋•Œ, var ctx = new ClassPa..

๐Ÿ’ Spring/Spring ํ•ต์‹ฌ ๊ธฐ์ˆ 

10. IoC ์ปจํ…Œ์ด๋„ˆ 9๋ถ€ : ResourceLoader

๋ฆฌ์†Œ์Šค๋ฅผ ์ฝ์–ด์˜ค๋Š” ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•˜๋Š” ์ธํ„ฐํŽ˜์ด์Šค ApplicationContext extends ResourceLoarder ๋ฆฌ์†Œ์Šค ์ฝ์–ด์˜ค๊ธฐ ํŒŒ์ผ ์‹œ์Šคํ…œ์—์„œ ์ฝ์–ด์˜ค๊ธฐ ํด๋ž˜์ŠคํŒจ์Šค์—์„œ ์ฝ์–ด์˜ค๊ธฐ URL๋กœ ์ฝ์–ด์˜ค๊ธฐ ์ƒ๋Œ€/์ ˆ๋Œ€ ๊ฒฝ๋กœ๋กœ ์ฝ์–ด์˜ค๊ธฐ resource.exists(); @Component public class AppRunner implements ApplicationRunner { @Autowired ResourceLoader resourceLoader; @Override public void run(ApplicationArguments args) throws Exception { Resource resource = resourceLoader.getResource("classpath:test.txt");//..

๐Ÿ’ Spring/Spring ํ•ต์‹ฌ ๊ธฐ์ˆ 

9. IoC ์ปจํ…Œ์ด๋„ˆ 8๋ถ€ : ApplicationEventPublisher

์ด๋ฒคํŠธ ํ”„๋กœ๊ทธ๋ž˜๋ฐ์— ํ•„์š”ํ•œ ์ธํ„ฐํŽ˜์ด์Šค ์ œ๊ณต. ์˜ต์ €๋ฒ„ ํŒจํ„ด ๊ตฌํ˜„์ฒด ApplicationContext extends ApplicationEventPublisher publishEvent(ApplicationEvent event) [event ์ฒ˜๋ฆฌ ๊ณผ์ •] SpringBootApplication์ด ๊ตฌ๋™ -> AppRunner๊ฐ€ ์‹คํ–‰์ด ๋˜๋ฉด์„œ -> event ๋ฐœ์ƒ! -> ๋ฐœ์ƒํ•œ event๋ฅผ ๋“ฑ๋ก๋˜์–ด์žˆ๋Š” ๋นˆ ์ค‘์—์„œ MyEvent๊ฐ€ ๋ฐ›์•„์„œ ์ฒ˜๋ฆฌ. ์ด๋ฒคํŠธ ๋ฐœ์ƒ ์‹œํ‚ค๋Š” ๋ฐฉ๋ฒ• - ApplicationEventPublisher.publishEvent(); @Component public class AppRunner implements ApplicationRunner { @Autowired ApplicationContext ..

๐Ÿ’ Spring/Spring ํ•ต์‹ฌ ๊ธฐ์ˆ 

8. IoC ์ปจํ…Œ์ด๋„ˆ 7๋ถ€ : MessageSource

๊ตญ์ œํ™” (i18n) ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•˜๋Š” ์ธํ„ฐํŽ˜์ด์Šค. ApplicationContext extends MessageSource getMessage(String code, Object[] args, String, default, Locale, loc) ... ์Šคํ”„๋ง ๋ถ€ํŠธ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค๋ฉด ๋ณ„๋‹ค๋ฅธ ์„ค์ • ํ•„์š”์—†์ด messages.properties ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Œ messages.properties messages_ko_kr.properties ... @Component public class AppRunner implements ApplicationRunner { @Autowired MessageSource messageSource; @Override public void run(ApplicationArguments ..

iseunghan
'๐Ÿ’ Spring/Spring ํ•ต์‹ฌ ๊ธฐ์ˆ ' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๊ธ€ ๋ชฉ๋ก (2 Page)