๐Ÿ’ Spring

๐Ÿ’ 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 ..

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

7. IoC ์ปจํ…Œ์ด๋„ˆ 6๋ถ€ : Environment 2๋ถ€. ํ”„๋กœํผํ‹ฐ

ํ”„๋กœํผํ‹ฐ ๋‹ค์–‘ํ•œ ๋ฐฉ๋ฒ•์œผ๋กœ ์ •์˜ํ•  ์ˆ˜ ์žˆ๋Š” ์„ค์ •๊ฐ’ Environment์˜ ์—ญํ• ์€ ํ”„๋กœํผํ‹ฐ ์†Œ์Šค ์„ค์ • ๋ฐ ํ”„๋กœํผํ‹ฐ ๊ฐ’ ๊ฐ€์ ธ์˜ค๊ธฐ 1) ๋‹ค์–‘ํ•œ ๋ฐฉ๋ฒ•์œผ๋กœ ์ •์˜ํ•  ์ˆ˜ ์žˆ๋Š” ์„ค์ •๊ฐ’ 1-1. VM options ์„ค์ • VM options : -Dapp.name=spring5 ์„ค์ • @Component public class AppRunner implements ApplicationRunner { @Autowired ApplicationContext ctx; @Autowired BookRepository bookRepository; @Override public void run(ApplicationArguments args) throws Exception { Environment environment = ctx.getEnv..

iseunghan
'๐Ÿ’ Spring' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๊ธ€ ๋ชฉ๋ก (11 Page)