전체 글
-
[13] Data binding 추상화: Converter와 FormatterSpring/Spring 핵심 기술 2020. 4. 26. 07:56
//@Configuration public class WebConfig implements WebMvcConfigurer { @Override public void addFormatters(FormatterRegistry registry) { registry.addFormatter(new EventFormatter()); } } [Converter] PropertyEditor는 사용하기 복잡하고 Object 대 String의 변환만 지원한다는 한계가 있습니다. 하지만 data binding은 여러 종류의 서로다른 type간 변환을 필요로 하기 때문에 이를 개선하고자 등장한 것이 Converter interface입니다. Converter interface는 PropertyEditor의 상태정보를 제거해 ..
-
[12] 추상화 - Data Binding 추상화 : PropertyEditorSpring/Spring 핵심 기술 2020. 4. 23. 17:47
data binding은 어떤 Property의 값을 target 객체에 설정하는 기능을 말합니다. 즉, 사용자가 입력한 값을 application domain 객체에 동적으로 할당하는 기능입니다. 이과 같은 동적인 할당에 data binding이 필요한 이유는 사용자가 입력한 값이 주로 문자열이고 이런 문자열을 객체가 가지고 있는 다양한 type의 field, 심지어 domain 객체 자체에 대해서도 대응하도록 변환해야 하는 경우가 발생하기 때문입니다. 요약하자면 type이 맞지 않는 data들 사이에서 data의 대입이 가능하도록 type을 변환해주는 기능을 data binding이라고 부릅니다. 이 data binding을 지원해주는 Spring interface가 DataBinder(org.spr..
-
[11] 추상화 - Validation 추상화Spring/Spring 핵심 기술 2020. 4. 22. 09:55
org.springframework.validation.Validator는 application에 사용하는 data 검증용 interface입니다. Validator는 주로 springMVC에서 사용하지만 web 계층 전용 Validator는 아닙니다. web, service, data 모든 계증에서 사용할 수 있는 일반적인 interface 입니다. 객체 data의 validation check를 위해 bean validation이 지원하는 validation용 annotation을 사용하거나 직접 validator를 만들어 사용할 수 있습니다. 더보기 *Bean Validation의 정의 bean validation은 JavaBean을 검증하기 위한 metadata model과 API입니다. meta..
-
[10] 추상화 - Resource 추상화Spring/Spring 핵심 기술 2020. 4. 21. 09:51
SpringFramework에서는 java.net.URL interface를 org.springframework.core.io.Resource interface type으로 상속 받아 추상화합니다. java.net.URL에는 resource 접근과 관리에 대한 기능이 부족하여 org.springframework.core.io.Resource로의 추상화를 통해 필요한 기능들을 지원하고 있습니다. 다음은 부족한 기능들의 예입니다. class path 기준으로 resource를 읽어오는 기능이 필요하지만 java.net.URL에서는 필요로 하는 기능을 제공하지 않습니다. java.net.URL에는 ServletContext를 기준으로 상대 경로를 읽어오는 기능이 없습니다. 새로운 핸들러를 등록하여 특별한 UR..
-
[09] ApplicationContext - ResourceLoaderSpring/Spring 핵심 기술 2020. 4. 21. 09:15
ResourceLoader는 이름과 같이 resource를 loading하는 기능을 제공하는 interface이며 ApplicationContext는 ResourceLoader를 상속받고 있어 ApplicationContext에서도 해당 기능을 사용할 수 있습니다. public interface ApplicationContext extends ResourcePatternResolver { ... } public interface ResourcePatternResolver extends ResourceLoader { ... } [resource 가져오기] ResourceLoader의 getResource() method는 Resource type의 객체를 반환 합니다. 다음은 getResource() me..
-
[08] ApplicationContext - ApplicationEventPublisherSpring/Spring 핵심 기술 2020. 4. 19. 09:25
Spring은 event programming을 위한 ApplicationEventPublisher라는 interface(옵저버 패턴 구현체)를 제공하고 있으며 ApplicationContext는 ApplicationEventPublisher를 상속받고 있습니다. 따라서 IoC Container에서 event programming을 위해 필요한 기능을 사용할 수 있습니다. [event의 정의] event를 정의하는 class를 먼저 만들어줍니다. 여기서는 MyEvent.java로 만들겠습니다. Spring 4.2 이전 버전에서는 ApplicationEvent라는 class를 상속받아 만듭니다. public class MyEvent extends ApplicationEvent { private int my..
-
[07] ApplicationContext - MessageSourceSpring/Spring 핵심 기술 2020. 4. 17. 09:06
MessageSource는 i18n 기능을 제공하는 interface로써 Message의 다국화 기능을 지원합니다. ApplicationContext는 MessageSource를 상속받으므로 해당하는 모든 기능을 ApplicationContext에서 사용할 수 있습니다. resources 아래에 "messages_" + Locale + ".properties" file (예: messages_ko_KR.properties)을 생성하고 message key, value pair들을 입력 후 build합니다(message resource 변경 후 build하지 않으면 변경사항이 적용되지 않음에 주의). 이후 Spring application 기동 시 ResourceBundleMessageSource에 의해 ..
-
[06] ApplicationContext - EnvironmentCapable interfaceSpring/Spring 핵심 기술 2020. 4. 16. 10:52
EnvironmentCapable은 Profile과 Property를 다루는 interface입니다. ApplicatioinContext는 EnvironmentCapable을 상속받기 때문에 IoC Container에서 Profile과 Property를 다룰 수 있습니다. public interface ApplicationContext extends EnvironmentCapable { ... } [Profile] Profile은 환경에 따라 사용할 bean들의 묶음을 미리 정해놓고 필요에 따라 선택하여 사용할 수 있는 기능을 말합니다. 이를 활용하여 개발환경과 배포환경 또는 각각의 다른 배포환경 별로 profile을 만들어 놓고 환경에 따라 원하는 profile로 전환하여 그에 상응하는 bean들로 a..