발 표 자소 개
•이 름 : 김 지 헌 (== honeymon)
ihoneymon@gmail.com
http://honeymon.io
이 노 트 리 (http://innotree.com) 근 무
KSUG 일 꾼 단 소 속 잡무 수 행
개 발 자 …
종 합레 저 스 포 츠 인 을 표 방
3.
Spring framework
● 2003,JDK 1.4
● https://spring.io/blog/2004/03
/24/spring-framework-1-0-
final-released
● Annotation, REST, SPAs,
WebSocket 가 요 구 되 기 전
Jackson 이 야기
• Jackson: JSON & XML 조 작
• Jackson2ObjectMapperBuilder 를 이 용 해 서
ObjectMapper 인 스 턴 스 를 생 성
• LastestJackon integration improvements
in spring
– @JsonView: Jackson's Serialization View
– JSONP: @ResponseEntity & ResponseEntity
20.
@RequestMapping
• java.util.Optional(JDK 8)지 원
• ResponseEntity/RequestEntity buider-style method
• MvcUriComponentBuilder를 사 용 하 여 다 른 컨 트 롤 러 의 메
서 드 를 호 출 할 수 있 는 URI 생 성
• @ModelAttribute 사 이 의 의 존 성 부 여
21.
정 적 자원 지 원
• ResourceHttpRequesthandler < 4.1
• ResourceResolver, ResourceTransformer, ResourceUrlProvider 4.1+
• 컨 텐 츠 기 반 해 시 를 가 진 Versioned URL
– e.g. "/css/font-awesome.min-7fbe76cdac.css"
• 보 다 자 세 한 사 항은 !!
– Resource Handling Spring MVC 4.1 - SpringOne 2014
– Resource handling Spring MVC - Adieu 2014, 봄 싹(박 용 권 )
22.
Groovy markup template
•HTML 템 플 릿 용 DSL을 Groovy 로 컴 파일
• Groovy 의 강력 한 힘 으 로 !
• See GroovyMarkup View
Javascript Templating + v4.2
23.
MVC 설 정
•ViewResolver 등 록 지 원
• ViewController 설 정
• Path matching 설 정
24.
비 동 기HTTP 요 청
• Servlet 3.0+ Async Request
• 클 라 이 언 트 에 이 벤 트 푸 시 , 긴 연 산
• 상 당 히 쉽 게 할 수 있 다 .
• 조 금 더 복 잡한 상 황에 대 해 서 는 구 현 이 어
려 움
25.
Web Messaging Architecture
•WebSocket -> Low-level transport
• SockJS -> fallback options
• STOMP -> application-level protocol
HTTP Streaming
• Newreturn type ResponseBodyEmitter
• Write a series of Objects to response body
• via HttpMessageConverter
• Also works with ResponseEntity
31.
HTTP Streaming Example
@RequestMapping
publicResponseBodyEmitter handle() {
ResponseBodyEmitter emitter = new ResponseBodyEmitter();
// …
return emitter;
}
// Later from some other thread
emitter.send(new Foo());
emitter.send(new Bar());
emitter.complete()
32.
HTTP Streaming: SSE-style
•SseEmitter extends ResponseBodyEmitter
• ResponseBodyEmitter와 같은 동 작 을 하 지
만 다 른 점 하 나 !
– SSE-style: W3C Server-Send Event
specifications
33.
Server-sent events example
@RequestMapping
publicSseEmitter handle() {
SseEmitter emitter = new SseEmitter();
// ...
return emitter;
}
// Later from some other thread
emitter.send(event().name("foo").data(new Foo()));
emitter.send(event().name("bar").data(new Bar()));
emitter.complete();
34.
HTTP Streaming: Directlyto Response
@RequestMapping
public StreamingResponseBody handle() {
return new StreamingResponseBody() {
@Override
public void writeTo(OutputStream out) {
// ...
}
}
}
35.
HTTP caching update
•CacheControl builder
• Configurable in various places
– WebContentGenerator/Interceptor
– ResourceHttpRequestHandler
– ResponseEntity
• Improved ETag/Last-Modified support in
WebRequest
36.
CORS support
• 계층 적 인 접 근
• 세 밀 한 설 정
– @CrossOrigin 컨 트 롤 러 에 사 용
• URL 패 턴 을 기 반 으 로 한 전 역 설 정
37.
How CORS issupported
• AbstractHandlerMapping 에 의 해 생 성
• 하 위 클 래 스 에 대 한 CORS 메 타 데 이 터 제 공
– @CrossOrigin
– CorsConfigurationSource
• AbstractHandlerMapping 안 에
CorsProcessor 설 정
– CORS 체 크 수 행 , 응 답 헤 더 설 정
38.
@RequestMapping meta annotation
@RequestMapping(method= RequestMethod.POST, produces =
MediaType.APPLICATION_JSON_VALUE, consumes =
MediaType.APPLICATION_JSON_VALUE)
public @interface PostJson {
String value() default "";
}
//..
@PostJson("/account")
public ResponseEntity<Account> add(Account account) {
return ResponseEntity.ok(account);
}
39.
Javascript View Templating
•Server and Client-side rendering
– using same template engine(e.g. React)
• `ScriptTemplateView`, `ViewResolver`
– built on Nashorn(JDK 1.8)
• 서 버 에 서 초 기 화해 두 고 , 서 버 에 서 가 져 온
코 드 를 가 지 고 클 라 이 언 트 사 이 드 에 서 랜
더 링
다 음 세 션 !! + 정 성 용 Isomorphic!!
40.
MISC == 기타 등 등
• 정 적 자 원 에 대 한 byte-range 요 청 지 원
• @ExceptionHandler 메 서 드 에 메 서 드 인 자
로 HandlerMethod 사 용
• MvcUriComponentsBuilder custom baseUri
41.
STOMP/WebSocket
• @ControllerAdvice 기반 으 로 메 서 드 전 역 에
@Exceptionhandler 적 용 가 능
• @SendTo/SendToUser Destination value
placehodler 정 의 : @DestinationVariable
• 다 중 앱 서 버 사 이 에 서 사 용 자 목 적 지 사 용
• SockJS 내 에 서 CORS 향상
발 표 자료
• 예 제 :
– https://github.com/ihoneymon/rocking-the-
spring-4x-web-application
47.
참 조 자료
• Spring Framework - wikipedia
• 4.0.0 release
• Spring 4 Web applications
• Spring Framework 4.0 Web Applications - SpringOne 2014
• Overview of Spring 4.0 - 박 용 권 , KSUG
• Spring MVC 4.2: New and Noteworthy
• Workshop - From Spring 4.0 To 4.2
• Exception handling in Spring MVC
• Spring - Modify response headers after controller processing
• Using WebSocket to build an interactive web application
• CORS support in Spring Framework
• Isomorphic templating with Spring Boot, Nashorn and React
• Script template
• HTTP Streaming