Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Spring Framework 4.1 Sébastien Deleuze, Spring Framework commiter, Pivotal @sdeleuze Built from SpringOne slides for Brian Clozel, Juergen Hoeller, Rossen Stoyanchev and Stéphane Nicoll
§ Java EE 6+ (but still Servlet 2.5 compliant) § Recommended § Java 8 § Java EE 7 § Version status § 4.1: current § 4.0: maintenance § 3.2: EOL
+ @ResponseBody § @ResponseBody “inherited” on method level @RestController class UserController { ! @RequestMapping("/user") public User getUser() { return new User("eric", "7!#H2"); } ! }
Auto-detected, just declare it as a bean § Fine-grained control @ControllerAdvice(basePackageClasses=MyController.class) @ControllerAdvice class GlobalControllerExceptionHandler { ! @ResponseStatus(HttpStatus.CONFLICT) @ExceptionHandler(DataIntegrityViolationException.class) public void handleConflict() { } ! }
Supported on @RequestMapping methods in 4.1 return instead of DeferredResult § Java 8 lambda compatible in 4.1 listenableFuture.addCallback(result -‐> ... , ex -‐> ...);
used in Spring Android § Google Protocol Buffers effective inter-service communication data protocol § Jackson / XML just add jackson-dataformat-xml to classpath support @JsonView use Jackson and JAXB annotations @XmlRootElement not needed anymore
String body = "Hello World"; HttpHeaders headers = new HttpHeaders() headers.setLocation(location); return new ResponseEntity<String>(body, headers, HttpStatus.CREATED); } public ResponseEntity<String> handle() { URI location = ...; return ResponseEntity.created(location).body("Hello World"); } Before After
§ Design to be used with Grunt/Gulp/etc. § Two new auxiliary strategies forming two chains • ResourceResolver • ResourceTransformer § ResourceUrlProvider determine “public” resource URL (e.g. insert version)
locations § VersionResourceResolver resolution with version in URL path § GzipResourceResolver lookup with .gz extension when “Accept-Encoding: gzip” § CachingResourceResolver caching of resolved resource
XHTML, HTML5) § DRY markup, Groovy DSL yieldUnescaped '<!DOCTYPE html>' html(lang:'en') { head { title('My page') } body { p('This is an example of HTML contents') } }
356 compliant runtimes (and more …) § Transparent SockJS layer § fall back on HTTP streaming or long polling § wide range of browser versions § Higher-level STOMP messaging enables @Controller-style programming model
org.springframework.messaging.Message is a generic message representation with headers and a body ! ! § Full access to body and headers for both inbound and outbound messages @JmsListener(destination = "order") @SendTo("orderStatus") public Message<OrderStatus> processOrder(Message<Order> order) {}
translation § No JMS API involved at all Message<Order> orderMessage = MessageBuilder. withPayload(order).setHeader("orderType", "sell").build(); messagingTemplate.send("order", orderMessage);