Slides from the Spring Framework 4.0 webinar as delivered on January 23rd, 2014. This deck covers the state of the Spring Framework 4.0.1 release, scheduled for release a few days later.
3 The State of the Art @Service public class MyBookAdminService implements BookAdminService { @Autowired public MyBookAdminService(AccountRepository repo) { ... } @Transactional public BookUpdate updateBook(Addendum addendum) { ... } }
6 Matching an Injection Point to a Factory Method @Service public class MyBookAdminService implements BookAdminService { @Autowired @Qualifier("production") public MyBookAdminService(AccountRepository repo) { ... } } @Bean @Qualifier("production") public AccountRepository myAccountRepository() { return new MyAccountRepositoryImpl(); }
7 Annotated MVC Controllers @Controller public class MyMvcController { @RequestMapping(value="/books/{id}", method=GET) public Book findBook(@PathVariable long id) { return this.bookAdminService.findBook(id); } @RequestMapping("/books/new") public void newBook(Book book) { this.bookAdminService.storeBook(book); } }
9 Introducing Spring Framework 4.0 ■ Ready for new application architectures ● embedded web servers and non-traditional datastores ● lightweight messaging and WebSocket-style architectures ● custom asynchronous processing with convenient APIs ■ A new baseline ● Java SE 6+ (minimum API level: JDK 6 update 18, ~ early 2010) ● Java EE 6+ (Servlet 3.0 focused, Servlet 2.5 compatible at runtime) ● all deprecated packages removed ● many deprecated methods removed as well
10 Spring Framework 4 and Java 8 ■ First-class support for Java 8 language and API features ● lambda expressions ● method references ● JSR-310 Date and Time ● repeatable annotations ● parameter name discovery ■ Full runtime compatibility with JDK 8 ● for Spring apps built against JDK 6/7 but running against JDK 8 ● when moving existing apps to a JDK 8 based deployment platform
12 Lambdas with Spring's JdbcTemplate JdbcTemplate jt = new JdbcTemplate(dataSource); jt.query("SELECT name, age FROM person WHERE dep = ?", ps -> ps.setString(1, "Sales"), (rs, rowNum) -> new Person(rs.getString(1), rs.getInt(2))); jt.query("SELECT name, age FROM person WHERE dep = ?", ps -> { ps.setString(1, "Sales"); }, (rs, rowNum) -> { return new Person(rs.getString(1), rs.getInt(2)); });
13 JSR-310 Date and Time import java.time.*; import org.springframework.format.annotation.*; public class Customer { // @DateTimeFormat(iso=ISO.DATE) private LocalDate birthDate; @DateTimeFormat(pattern="M/d/yy h:mm") private LocalDateTime lastContact; ... }
16 Conditional Bean Definitions ■ A generalized model for conditional bean definitions ● a more flexible and more dynamic variant of bean definition profiles (as known from Spring 3.1) ● can e.g. be used for smart defaulting ● see Spring Boot (projects.spring.io/spring-boot) ■ @Conditional with programmatic Condition implementations ● can react to rich context (existing bean definitions etc) ● profile support now simply a ProfileCondition impl class ● enabling new deployment styles
19 Many Further Container Refinements ■ @Autowired @Lazy on injection points ● requesting a lazy-initialization proxy individually per injection point ■ Ordered injection of arrays and lists ● sorting injected beans by Ordered / @Order ■ Target-class proxies for classes with arbitrary constructors ● creating CGLIB proxies using Objenesis, not invoking any constructor ■ Composable annotations in the test context framework ● e.g. @ContextConfiguration, @WebAppConfiguration, @ActiveProfiles ■ Time zone management with dedicated Spring MVC support ● through LocaleContextResolver and TimeZoneAwareLocaleContext
20 Messaging, WebSocket, Async Processing ■ General org.springframework.messaging module ● core message and channel abstractions ● endpoints using generic messaging patterns ■ WebSocket endpoint model along the lines of Spring MVC ● JSR-356 and native server support, with SockJS fallback option ● STOMP for higher-level messaging on top of raw WebSocket ■ AsyncRestTemplate ● based on ListenableFuture return values
22 Higher-Level Messaging: STOMP on WebSocket @Controller public class MyStompController { @SubscribeEvent("/positions") public List getPortfolios(Principal user) { ... } @MessageMapping("/trade") public void executeTrade(Trade trade, Principal user) { ... } }
24 Common Server Generations and Third-Party Libraries ■ Tomcat 6.0.33+ (WebSocket on Tomcat 7.0.47+ and 8.0) ■ Jetty 7.5+ (WebSocket on Jetty 9.0 and 9.1) ■ JBoss 6.1+ (WebSocket on WildFly 8.0) ■ GlassFish 3.1+ (WebSocket on GlassFish 4.0) ■ WebLogic 10.3.4+ (with JPA 2.0 patch applied) ■ WebSphere 7.0.0.9+ (with JPA 2.0 feature pack) ■ We generally support library versions <=3 years back ● Spring Framework 4.0: minimum versions ~ early 2011 ● e.g. Hibernate 3.6+, EhCache 2.1+, Quartz 1.8+, Jackson 1.8+
25 To Upgrade or Not To Upgrade? ■ Spring 3.2.x does not support the 1.8 bytecode level ● However, it does support running JDK 6/7 based apps on JDK 8 ■ We strongly recommend an early upgrade to Spring 4 ● Spring Framework 3.2 is in maintenance mode already ● See github.com/spring-projects/spring-framework/wiki/ Migrating-from-earlier-versions-of-the-Spring-Framework ■ Spring Framework 4.0 GA released in December 2013 ■ Spring Framework 4.0.1 to be released on Monday (January 27th) ■ Spring Framework 4.0.2 scheduled for late March 2014
26 Next Iteration: Spring Framework 4.1 ■ Comprehensive web resource handling ● resource pipelining, cache control refinements ■ Caching support revisited ● alignment with JCache 1.0 final, user-requested enhancements ■ JMS support overhaul ● alignment with messaging module, annotation-driven endpoints ■ Performance improvements ● application startup, SpEL expression evaluation ■ Spring Framework 4.1 RC1 in June 2014 ■ Spring Framework 4.1 GA in August 2014
27 Learn More. Stay Connected. ■ Core framework: projects.spring.io/spring-framework ■ Check out Spring Boot: projects.spring.io/spring-boot ■ Upcoming releases: Spring Framework 4.0.1 on Jan 27 Spring Framework 4.0.2 on Mar 25 Twitter: twitter.com/springcentral YouTube: spring.io/video LinkedIn: spring.io/linkedin Google Plus: spring.io/gplus