2 2 www.springsource.org Review: Spring 3 Component Model Themes Powerful annotated component model • stereotypes, configuration classes, composable annotations Spring Expression Language • and its use in value injection Comprehensive REST support • and other Spring @MVC additions Support for async MVC processing • Spring MVC interacting with Servlet 3.0 async callbacks Declarative validation and formatting • integration with JSR-303 Bean Validation Declarative scheduling • trigger abstraction, cron support Declarative caching
6 6 www.springsource.org Next Stop: Spring Framework 4.0 First-class support for Java 8 language and API features • lambda expressions, method references • JSR-310 Date and Time, etc A generalized model for conditional bean definitions • a more flexible and more dynamic variant of bean definition profiles First-class support for Groovy (in particular: Groovy 2) • Groovy-based bean definitions (a.k.a. Grails Bean Builder) • runtime support for regular Spring beans implemented in Groovy A WebSocket endpoint model along the lines of Spring MVC • deploying Spring-defined endpoint beans to a WebSocket runtime
8 8 www.springsource.org Spring and Common Java SE Generations Spring 2.5 introduced Java 6 support • JDK 1.4 – JDK 6 Spring 3.0 raised the bar to Java 5+ • JDK 5 – JDK 6 Spring 3.1/3.2: explicit Java 7 support • JDK 5 – JDK 7 Spring 4.0 introducing explicit Java 8 support now • JDK 6 – JDK 8
9 9 www.springsource.org Spring and Common Java EE Generations Spring 2.5 completed Java EE 5 support • J2EE 1.3 – Java EE 5 Spring 3.0 introduced Java EE 6 support • J2EE 1.4 – Java EE 6 Spring 3.1/3.2: strong Servlet 3.0 focus • J2EE 1.4 (deprecated) – Java EE 6 Spring 4.0 introducing explicit Java EE 7 support now • Java EE 5 (with JPA 2.0 feature pack) – Java EE 7
10 10 www.springsource.org The State of Java 8 Delayed again... • scheduled for GA in September 2013 • now just Developer Preview in September • OpenJDK 8 GA as late as March 2014 (!) IDE support for Java 8 language features • IntelliJ: available since IDEA 12, released in December 2012 • Eclipse: announced for June 2014 (!) • Spring Tool Suite: trying to get some Eclipse-based support earlier Spring Framework 4.0 scheduled for GA in October 2013 • with best-effort Java 8 support on OpenJDK 8 Developer Preview
11 11 www.springsource.org JDK 8: Initial Problems 1.8 bytecode level • as generated by -target 1.8 (the compiler's default) • not accepted by ASM 4.x (Spring's bytecode parsing library) • Spring Framework 4.0 M1 comes with patched ASM 4.1 variant HashMap/HashSet implementation differences • different hash algorithms in use • leading to different hash iteration order • code shouldn't rely on such an order but sometimes accidentally does Note: Java 8 API features can be used with -target 1.7 as well • compatible with ASM 4.0, as used in Spring Framework 3.2
12 12 www.springsource.org JSR-310 Date-Time Specialized date and time value types in java.time package • replacing java.util.Date/Calendar, along the lines of the Joda-Time project • Spring 4.0: annotation-driven date formatting public class Customer { // @DateTimeFormat(iso=ISO.DATE) private LocalDate birthDate; @DateTimeFormat(pattern="M/d/yy h:mm") private LocalDateTime lastContact; }
14 14 www.springsource.org 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, "test"); }, (rs, rowNum) -> { return new Person(rs.getString(1), rs.getInt(2)); }); Java 8 Lambdas with Spring's JdbcTemplate
15 15 www.springsource.org public List getPersonList(String department) { JdbcTemplate jt = new JdbcTemplate(this.dataSource); return jt.query( "SELECT name, age FROM person WHERE dep = ?", ps -> { ps.setString(1, "test"); }, this::mapPerson); } private Person mapPerson(ResultSet rs, int rowNum) throws SQLException { return new Person(rs.getString(1), rs.getInt(2)); } Java 8 Method References with Spring's JdbcTemplate
16 16 www.springsource.org The State of Java 8, Revisited Current OpenJDK 8 builds work quite well for our purposes • JSR-310's java.time package is near completion • lambdas and method references work great • currently using b88 (due to AspectJ compiler problems with b89+) IntelliJ IDEA 12 is quite advanced in terms of Java 8 support • can replace anonymous inner class with lambda if possible • can auto-complete method reference • works fine with any recent OpenJDK 8 build No support for 1.8 bytecode in Gradle's test class detection yet • Gradle is using an unpatched version of ASM 4.0
18 18 www.springsource.org Spring Framework 4.0 M2: July 2013 Initial Groovy support story • Groovy-based bean definitions, some AOP refinements Up-to-date Java 8 support based on feature-complete OpenJDK 8 • including latest lambda compiler and lambda-based stream APIs Enterprise specs (EE 7 level) • support for the final API releases (following the EE 7 release in June) Second iteration of conditional bean definitions Annotation-based message endpoint model (-> WebSocket)