Your SlideShare is downloading. ×
Spring 4 on Java 8
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Saving this for later?

Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime - even offline.

Text the download link to your phone

Standard text messaging rates apply

Spring 4 on Java 8

1,231
views

Published on

Video and slides synchronized, mp3 and slide download available at URL http://bit.ly/1l0qYVQ. …

Video and slides synchronized, mp3 and slide download available at URL http://bit.ly/1l0qYVQ.

Juergen Hoeller introduces Spring 4 and illustrates selected Java 8 features in interaction with Spring's programming model, exploring their immediate practical impact. Filmed at qconnewyork.com.

Juergen Hoeller is co-founder of the Spring Framework open source project and has been serving as the project lead and release manager for the core framework since 2003. Juergen is an experienced software architect and consultant with outstanding expertise in code organization, transaction management and enterprise messaging.

Published in: Technology

0 Comments
13 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,231
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
0
Comments
0
Likes
13
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Spring Framework 4 on Java 8 Juergen Hoeller Spring Framework Lead Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.1 org/licenses/by-nc/3.0/ Pivotal Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
  • 2. Watch the video with slide synchronization on InfoQ.com! http://www.infoq.com/presentations /spring-4-java8 InfoQ.com: News & Community Site • 750,000 unique visitors/month • Published in 4 languages (English, Chinese, Japanese and Brazilian Portuguese) • Post content from our QCon conferences • News 15-20 / week • Articles 3-4 / week • Presentations (videos) 12-15 / week • Interviews 2-3 / week • Books 1 / month
  • 3. Presented at QCon New York www.qconnewyork.com Purpose of QCon - to empower software development by facilitating the spread of knowledge and innovation Strategy - practitioner-driven conference designed for YOU: influencers of change and innovation in your teams - speakers and topics driving the evolution and innovation - connecting and catalyzing the influencers and innovators Highlights - attended by more than 12,000 delegates since 2007 - held in 9 cities worldwide
  • 4. The State of the Art: Component Classes @Service @Lazy public class MyBookAdminService implements BookAdminService { @Autowired public MyBookAdminService(AccountRepository repo) { ... } @Transactional public BookUpdate updateBook(Addendum addendum) { ... } } Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.2 org/licenses/by-nc/3.0/
  • 5. The State of the Art: Configuration Classes @Configuration @Profile("standalone") @EnableTransactionManagement public class MyBookAdminConfig { @Bean @Scope("session") public BookAdminService myBookAdminService() { MyBookAdminService service = new MyBookAdminService(); service.setDataSource(bookAdminDataSource()); return service; } ... } Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.3 org/licenses/by-nc/3.0/
  • 6. SPRING IO CORE: Introducing Spring Framework 4.0 Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.4 org/licenses/by-nc/3.0/ Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
  • 7. 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) ● comprehensive support for Java SE 8 (language features and APIs) ● explicit support for Java EE 7 level specifications (JMS 2.0, JTA 1.2, JPA 2.1, Bean Validation 1.1, JSR-236 Concurrency) Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.5 org/licenses/by-nc/3.0/
  • 8. Generics-based Injection Matching @Service public class MyBookAdminService implements BookAdminService { @Autowired public MyBookAdminService(MyRepository<Account> repo) { ... } } @Bean public MyRepository<Account> myAccountRepository() { return new MyAccountRepositoryImpl(); } Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.6 org/licenses/by-nc/3.0/
  • 9. Many Further Container Refinements ■ Composable annotations with overridable attributes ● e.g. custom scope annotation with proxyMode attribute ■ A generalized model for conditional bean definitions ● based on @Conditional; see Spring Boot (projects.spring.io/spring-boot) ■ @Autowired @Lazy on injection points ● requesting a lazy-initialization proxy individually per injection point ■ Target-class proxies for classes with arbitrary constructors ● creating CGLIB proxies using Objenesis, not invoking any constructor Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.7 org/licenses/by-nc/3.0/
  • 10. Messaging & WebSocket ■ General org.springframework.messaging module ● core message and channel abstractions ● endpoints using generic messaging patterns ● @MessageMapping and co for annotated endpoints ■ WebSocket endpoint model along the lines of Spring MVC ● JSR-356 support for raw WebSocket handling ● flexible endpoints through native server support (Tomcat 7/8, Jetty 9, GlassFish 4, WildFly 8) ● transparent SockJS fallback option ● STOMP for higher-level messaging on top of a WebSocket channel Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.8 org/licenses/by-nc/3.0/
  • 11. SPRING IO CORE: Spring Framework 4 and Java 8 Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.9 org/licenses/by-nc/3.0/ Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
  • 12. 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 Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.10 org/licenses/by-nc/3.0/
  • 13. Lambda Conventions in Spring APIs ■ JdbcTemplate ● PreparedStatementSetter: void setValues(PreparedStatement ps) throws SQLException ● RowMapper: Object mapRow(ResultSet rs, int rowNum) throws SQLException ■ JmsTemplate ● MessageCreator: Message createMessage(Session session) throws JMSException ■ TransactionTemplate ● TransactionCallback: Object doInTransaction(TransactionStatus status) Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.11 org/licenses/by-nc/3.0/
  • 14. Lambdas with Spring's JdbcTemplate (v1) 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))); Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.12 org/licenses/by-nc/3.0/
  • 15. Lambdas with Spring's JdbcTemplate (v2) JdbcTemplate jt = 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)); }); Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.13 org/licenses/by-nc/3.0/
  • 16. Method References with Spring's JdbcTemplate public List<Person> getPersonList(String 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)); } Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.14 org/licenses/by-nc/3.0/
  • 17. 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; ... } Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.15 org/licenses/by-nc/3.0/
  • 18. Repeatable Annotations @Scheduled(cron = "0 0 12 * * ?") @Scheduled(cron = "0 0 18 * * ?") public void performTempFileCleanup() { ... } @Schedules({ @Scheduled(cron = "0 0 12 * * ?"), @Scheduled(cron = "0 0 18 * * ?") }) public void performTempFileCleanup() { ... } Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.16 org/licenses/by-nc/3.0/
  • 19. Parameter Name Discovery ■ Spring's DefaultParameterNameDiscoverer ● as of Spring Framework 4.0: aware of Java 8's parameter reflection ● now checking Java 8 first (-parameters) ● ASM-based reading of debug symbols next (-debug) @Controller public class MyMvcController { @RequestMapping(value="/books/{id}", method=GET) public Book findBook(@PathVariable long id) { return this.bookAdminService.findBook(id); } } Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.17 org/licenses/by-nc/3.0/
  • 20. SPRING IO CORE: Outlook: Spring Framework 4.1 Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.18 org/licenses/by-nc/3.0/ Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
  • 21. Key Themes for Spring Framework 4.1 ■ Comprehensive web resource handling ● cache control refinements, pluggable resource handler strategies ■ Caching support revisited ● alignment with JCache 1.0 annotations, user-requested enhancements ■ JMS support overhaul ● alignment with messaging module, annotation-driven endpoints ■ Spring Framework 4.1 GA scheduled for July 2014 Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.19 org/licenses/by-nc/3.0/
  • 22. Learn More. Stay Connected. ■ Core framework: projects.spring.io/spring-framework ■ Check out Spring Boot: projects.spring.io/spring-boot ■ Current and upcoming releases: Spring Framework 4.0.5 on May 20th Spring Framework 4.1 RC1 on July 1st Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.20 org/licenses/by-nc/3.0/ Twitter: twitter.com/springcentral YouTube: spring.io/video LinkedIn: spring.io/linkedin Google Plus: spring.io/gplus
  • 23. Watch the video with slide synchronization on InfoQ.com! http://www.infoq.com/presentations/spring-4- java8