public class MyBookAdminService implements BookAdminService { @Autowired @Qualifier("production") public MyBookAdminService(AccountRepository ar) { ... } } @Bean @Qualifier("production") public AccountRepository myAccountRepository() { return new MyAccountRepositoryImpl(); }
@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); } }
– Java SE 6+ – Java EE 6+ (Servlet 3.0 focused, Servlet 2.5 compatible) – all deprecated packages removed – many deprecated methods removed as well • 3rd party open source libraries – minimum versions ~ mid 2010 now – e.g. Hibernate 3.6+, Quartz 1.8+, EhCache 2.1+
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
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 :-) • @Conditional with programmatic Condition implementations – can react to rich context (existing bean definitions etc) – profile support now simply a ProfileCondition impl class
extracted from Spring Integration – core message and channel abstractions • WebSocket endpoint model along the lines of Spring MVC – JSR-356 but also covering SockJS and STOMP – endpoints using generic messaging patterns • AsyncRestTemplate – based on ListenableFuture return values
– 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 Dec 2012 – Eclipse: announced in GA form for June 2014 (!) – Spring Tool Suite: Eclipse-based beta support already
APIs are candidates for lambdas – through naturally following the lambda interface conventions – formerly "single abstract method" types – now "functional interfaces" • Simple rule: interface with single method – typically callback interfaces – for a reference: Runnable, Callable – several new common interfaces introduced in Java 8
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)));
new JdbcTemplate(dataSource); 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)); });
department) { JdbcTemplate jt = new JdbcTemplate(this.dataSource); return jt.query("SELECT name, age FROM person WHERE dep = ?", ps -> ps.setString(1, "Sales"), this::mapPerson); } private Person mapPerson(ResultSet rs, int rowNum) throws SQLException { return new Person(rs.getString(1), rs.getInt(2)); }
rich Parameter reflection type for methods – application sources to be compiled with -parameters • Spring's StandardReflectionParameterNameDiscoverer – reading parameter names via Java 8's new Parameter type • Spring's DefaultParameterNameDiscoverer – now checking Java 8 first (-parameters) – ASM-based reading of debug symbols next (-debug)
OpenJDK 8 builds work perfectly for our purposes – lambdas and method references work great – OpenJDK 8 is beyond its API freeze point already • IntelliJ IDEA 12 is quite advanced in terms of Java 8 support – works fine with any recent OpenJDK 8 build • Spring Framework 4.0 to go GA before OpenJDK 8 GA – against the OpenJDK 8 Developer Preview release – providing best-effort support for starting Java 8 based apps
3.2 does not support the 1.8 bytecode level – upgrade to Spring 4.0 to enable Java 8 language features • We strongly recommend an early upgrade to Spring 4 – Spring Framework 4.0 is still compatible with JDK 6 and 7 – Spring Framework 3.2 in maintenance mode already • Spring Framework 4.0 RC1 released at the end of October • Spring Framework 4.0 GA to be released in December