๐ Spring/Spring ํต์ฌ ๊ธฐ์
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 ํต์ฌ ๊ธฐ์
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 ํต์ฌ ๊ธฐ์
๋ฆฌ์์ค๋ฅผ ์ฝ์ด์ค๋ ๊ธฐ๋ฅ์ ์ ๊ณตํ๋ ์ธํฐํ์ด์ค 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 ํต์ฌ ๊ธฐ์
์ด๋ฒคํธ ํ๋ก๊ทธ๋๋ฐ์ ํ์ํ ์ธํฐํ์ด์ค ์ ๊ณต. ์ต์ ๋ฒ ํจํด ๊ตฌํ์ฒด ApplicationContext extends ApplicationEventPublisher publishEvent(ApplicationEvent event) [event ์ฒ๋ฆฌ ๊ณผ์ ] SpringBootApplication์ด ๊ตฌ๋ -> AppRunner๊ฐ ์คํ์ด ๋๋ฉด์ -> event ๋ฐ์! -> ๋ฐ์ํ event๋ฅผ ๋ฑ๋ก๋์ด์๋ ๋น ์ค์์ MyEvent๊ฐ ๋ฐ์์ ์ฒ๋ฆฌ. ์ด๋ฒคํธ ๋ฐ์ ์ํค๋ ๋ฐฉ๋ฒ - ApplicationEventPublisher.publishEvent(); @Component public class AppRunner implements ApplicationRunner { @Autowired ApplicationContext ..
๐ Spring/Spring ํต์ฌ ๊ธฐ์
๊ตญ์ ํ (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 ํต์ฌ ๊ธฐ์
ํ๋กํผํฐ ๋ค์ํ ๋ฐฉ๋ฒ์ผ๋ก ์ ์ํ ์ ์๋ ์ค์ ๊ฐ 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..