Spring/Spring 핵심 기술
-
[17] Null-SafetySpring/Spring 핵심 기술 2020. 5. 7. 18:34
Spring framework 5부터 compile time에 NullPointException을 최대한 방지하기 위한 annotation이 지원되고 있습니다. [Null-Safety 관련 annotation] @NonNull : 변수나 return value에 null을 허용하지 않을 경우 사용합니다. org.springframework.lang의 @NonNull을 사용해야 합니다. @Nullable : 변수나 return value에 null을 허용하는 경우 사용합니다. @NonNull과 마찬가지로 org.springframework.lang에 해당하는 annotation을 사용합니다. [Null-safety annotation 사용 위치] 변수 값의 null 허용 여부 : null을 확인할 변수 앞..
-
[16] Spring AOP (Proxy-based AOP)Spring/Spring 핵심 기술 2020. 5. 4. 08:54
Spring AOP는 Spring bean에만 적용할 수 있는 proxy pattern의 AOP 구현체입니다. [Proxy Pattern이란?] Proxy pattern은 software design pattern 중 하나입니다. 일반적으로 proxy란 실제 객체(여기서는 Spring bean)에 대한 interface 역할을 수행하는 class의 객체를 말합니다. proxy와 resource는 동일한 interface type을 구현합니다. proxy와 실제 객체는 동일한 interface type이기 때문에 동일한 책임(method)을 수행할 수 있어야 합니다. 하지만 proxy는 직접 책임을 수행하지 않고 실제 객체가 대신 처리하도록 delegation 합니다. 그렇기 때문에 proxy는 실제 객체..
-
[15] Aspect Oriented Programming 의 개념Spring/Spring 핵심 기술 2020. 5. 2. 07:31
먼저 Aspect Oriented Programming관 관련된 용어를 정리하도록 하겠습니다. Aspect : aspect의 사전적 뜻은 "측면", "양상"입니다. programming code에서 동일한 양상의 code(crosscutting concerns)들을 한 곳에 모아 관리하는 것이 aspect 입니다. Target : aspect의 advice(code)를 적용할 대상입니다. Advice : concern들을 모아 aspect에서 관리하는 code입니다. aspect를 통해 target에서 수행됩니다. Join point : code의 흐름 중 aspect의 advice를 적용할 point 입니다. 생성자 호출 직전, 생성자 호출 시, field 접근 전 filed에서 값을 가져갔을 때 me..
-
[14] Spring Expression Language (SpEL)Spring/Spring 핵심 기술 2020. 4. 29. 09:42
Spring Expression Language는 객체 graph를 조회하고 조작하는 기능을 제공하는 expression language입니다. method 호출과 문자열 template 기능을 제공하며 Spring project 전반에 걸쳐 사용할 목적으로 만들어졌습니다. SpEL의 구성 ExpressionParser parser = new SpelExpressionParser() StandardEvaluationContext context = new Standard EvaluationContext (bean)-->EvalucationContext를 통해 등록된 bean의 method는 SpEL을 통해 접근할 수 있습니다. Expression expression = parser.parseExpressi..
-
[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..