Diese Präsentation wurde erfolgreich gemeldet.
Wir verwenden Ihre LinkedIn Profilangaben und Informationen zu Ihren Aktivitäten, um Anzeigen zu personalisieren und Ihnen relevantere Inhalte anzuzeigen. Sie können Ihre Anzeigeneinstellungen jederzeit ändern.
Spring Framework 4.0
The Next Generation
Sam Brannen
@sam_brannen
Sam Brannen
•  Spring and Java Consultant @ Swiftmind
•  Java Developer for over 15 years
•  Spring Framework Core Committ...
Swiftmind: Areas of Expertise
•  Spring Framework
•  Java EE
•  OSGi
•  Agile Methodologies
•  Software Engineering Best P...
Swiftmind: How to find us
•  Zurich, Switzerland
•  Twitter: @swiftmind
•  http://www.swiftmind.com

|
A Show of Hands…

|
Agenda
•  Spring 3.x in Review
•  Themes in 4.0
•  Java EE
•  Java SE
•  Spring 4 on Java 8
|
Spring 3.x: Component Model
•  Powerful annotated component model
•  stereotypes, configuration classes, composable
annota...
Spring 3.x: Component Model
•  Comprehensive REST support
•  and other Spring @MVC additions

•  Support for async MVC pro...
Spring 3.x: Component Model
•  Declarative validation and formatting
•  integration with JSR-303 Bean Validation

•  Decla...
Spring 3.x: Testing
•  Embedded databases via <jdbc /> namespace
•  @Configuration classes & @ActiveProfiles
•  @WebAppCon...
Spring 3.x: Key Specifications
•  JSR-330 (Dependency Injection for Java)
•  @Inject, @Qualifier, Provider mechanism

•  J...
Spring 3.x: Key Specifications
•  JPA 2.0
•  persistence provider integration
•  Spring transactions

•  Servlet 3.0
•  we...
Typical Annotated Component

|
Composable Stereotypes
•  Combining meta-annotations on a custom stereotype
•  Automatically detected: no configuration ne...
Configuration Classes

|
Spring 4.0 Themes

|
New Baseline
•  Java SE 6+
•  Java EE 6+ (Servlet 3.0 focused, Servlet 2.5
compatible)
•  All deprecated packages removed
...
Third-party Libraries
•  Minimum versions ~ mid 2010 now
•  For example
•  Hibernate 3.6+
•  Quartz 1.8+
•  Ehcache 2.1+

...
Java 8 Language & API Features
•  Lambda expressions
•  Method references
•  JSR-310 Date and Time
•  Repeatable annotatio...
Groovy + Spring 4.0
•  A smooth out-of-the-box experience for
Groovy-based Spring applications

|
Groovy + Spring 4.0
•  AOP adaptations
•  special handling of GroovyObject calls
•  consider a Spring application with all...
Groovy + Spring 4.0
•  Groovy-based bean definitions
•  formerly known as the Bean Builder in Grails
•  now to live alongs...
Conditional Bean Definitions
•  A generalized model for conditional bean
definitions
•  a more flexible and more dynamic v...
Conditional Bean Definitions
•  @Conditional with programmatic Condition
implementations
•  can react to rich context (exi...
Annotation-based Components
•  Custom annotations may override specific
attributes of meta-annotations
•  Purely conventio...
Annotation-based Components
@MyTransactional(readOnly=true)	
	
@MySessionScope(scopedProxyMode=TARGET_CLASS)
	

|
Lazy Resolution Proxies
•  @Lazy on injection point
•  Alternative to Provider<MyTargetType>

|
Ordered Injection of Lists & Arrays
•  Ordered/@Order on candidate beans
•  Relative order within specific injection resul...
DI and Generics
•  Type matching based on full generic type
•  e.g. MyRepository<Customer>

•  Generic factory methods sup...
spring-messaging
•  New org.springframework.messaging module
•  Extracted from Spring Integration
•  Core message and chan...
WebSockets
•  WebSocket endpoint model along the lines of
Spring MVC
•  JSR-356 but also covering SockJS and STOMP
•  Endp...
AsyncRestTemplate
•  Analogous to existing RestTemplate
•  Based on ListenableFuture return values

|
Spring and Java EE

|
Java EE Support (1/2)
•  Spring 2.5 completed Java EE 5 support
•  J2EE 1.3 – Java EE 5

•  Spring 3.0 introduced Java EE ...
Java EE Support (2/2)
•  Spring 3.1/3.2: strong Servlet 3.0 focus
•  J2EE 1.4 (deprecated) – Java EE 6

•  Spring 4.0 intr...
Enterprise APIs (1/2)
•  JMS 2.0
•  delivery delay, JMS 2.0 createSession() variants, etc.

•  JTA 1.2
•  javax.transactio...
Enterprise APIs (2/2)
•  JPA 2.1
•  unsynchronized persistence contexts

•  Bean Validation 1.1
•  method parameter and re...
Spring and Java SE

|
Java SE Support (1/2)
•  Spring 2.5 introduced Java 6 support
•  JDK 1.4 – JDK 6

•  Spring 3.0 raised the bar to Java 5+
...
Java SE Support (2/2)
•  Spring 3.1/3.2: explicit Java 7 support
•  JDK 5 – JDK 7

•  Spring 4.0 introduces explicit Java ...
Java 8 Programming Model

|
The State of Java 8
•  Delayed again...
•  Scheduled for GA in September 2013
•  Now just Developer Preview in September
•...
IDE Support for Java 8
•  IntelliJ: available since IDEA 12, released in
Dec 2012
•  Eclipse: announced for June 2014 (!)
...
Java 1.8 Bytecode Level
•  Generated by -target 1.8 (compiler's default)
•  Not accepted by ASM 4.x (Spring's bytecode
par...
HashMap/HashSet Differences
•  Different hash algorithms in use
•  Leading to different hash iteration order
•  Code shoul...
Java 8 Lambda Conventions
•  Simple rule: interface with single method
• 
• 
• 
• 

typically callback interfaces
for exam...
Lambda + Spring = Natural Fit
•  Many Spring APIs are candidates for lambdas
•  by naturally following the lambda interfac...
Lambdas with JMS APIs
•  JmsTemplate + MessageCreator:
•  Message createMessage(Session session) throws
JMSException

|
Lambdas with Tx APIs
•  TransactionTemplate + TransactionCallback:
•  Object doInTransaction(TransactionStatus status)

|
Lambdas with JDBC APIs
•  JdbcTemplate + RowMapper:
•  Object mapRow(ResultSet rs, int rowNum) throws
SQLException

|
Lambdas with JdbcTemplate #1
JdbcTemplate jt = new JdbcTemplate(dataSource);	
	
jt.query("SELECT name, age FROM person WHE...
Lambdas with JdbcTemplate #2
JdbcTemplate jt = new JdbcTemplate(dataSource);	
	
jt.query("SELECT name, age FROM person WHE...
Method References (1/2)
public List<Person> getPersonList(String department) {	
JdbcTemplate jt = new JdbcTemplate(this.da...
Method References (2/2)
private Person mapPerson(ResultSet rs, int rowNum)	
throws SQLException {	
return new Person(rs.ge...
JSR-310 Date and Time
import java.time.*;	
import org.springframework.format.annotation.*;	
	
public class Customer {	
// ...
Repeatable Annotations
@Scheduled(cron = "0 0 12 * * ?")	
@Scheduled(cron = "0 0 18 * * ?")	
public void performTempFileCl...
Parameter Name Discovery (1/2)
•  Java 8 defines a Parameter reflection type for methods
•  application sources to be comp...
Parameter Name Discovery (2/2)
•  Spring's StandardReflectionParameterNameDiscoverer
•  reading parameter names via Java 8...
In Closing…

|
Roadmap
•  Spring Framework 4.0 RC1: end of October
•  Spring Framework 4.0 RC2: mid November
•  Spring Framework 4.0 GA: ...
Upgrade Considerations
•  Spring 3.2 does not support 1.8 bytecode level
•  upgrade to Spring 4.0 to enable Java 8 languag...
Acknowledgements
Special thanks to Spring Framework project lead
Juergen Hoeller for permitting reuse of his content.

|
Spring Resources (1/2)
•  Spring Framework
•  http://projects.spring.io/spring-framework

•  Spring Forums
•  http://forum...
Spring Resources (2/2)
•  Spring JIRA
•  https://jira.springsource.org

•  Spring on GitHub
•  https://github.com/spring-p...
Blogs
•  Swiftmind Blog
•  http://www.swiftmind.com/blog

•  Spring Blog
•  http://spring.io/blog

|
Thanks for your attention!
@sam_brannen
sam.brannen@swiftmind.com
slideshare.net/sbrannen
www.
.com
Nächste SlideShare
Wird geladen in …5
×

JAZOON'13 - Sam Brannen - Spring Framework 4.0 - The Next Generation

1.627 Aufrufe

Veröffentlicht am

Veröffentlicht in: Technologie, Bildung
  • Als Erste(r) kommentieren

JAZOON'13 - Sam Brannen - Spring Framework 4.0 - The Next Generation

  1. 1. Spring Framework 4.0 The Next Generation Sam Brannen @sam_brannen
  2. 2. Sam Brannen •  Spring and Java Consultant @ Swiftmind •  Java Developer for over 15 years •  Spring Framework Core Committer since 2007 •  Spring Trainer •  Presenter on Spring, Java, OSGi, and testing |
  3. 3. Swiftmind: Areas of Expertise •  Spring Framework •  Java EE •  OSGi •  Agile Methodologies •  Software Engineering Best Practices |
  4. 4. Swiftmind: How to find us •  Zurich, Switzerland •  Twitter: @swiftmind •  http://www.swiftmind.com |
  5. 5. A Show of Hands… |
  6. 6. Agenda •  Spring 3.x in Review •  Themes in 4.0 •  Java EE •  Java SE •  Spring 4 on Java 8 |
  7. 7. Spring 3.x: Component Model •  Powerful annotated component model •  stereotypes, configuration classes, composable annotations, profiles •  Spring Expression Language •  and its use in @Value injection |
  8. 8. Spring 3.x: Component Model •  Comprehensive REST support •  and other Spring @MVC additions •  Support for async MVC processing •  Spring MVC interacting with Servlet 3.0 async callbacks |
  9. 9. Spring 3.x: Component Model •  Declarative validation and formatting •  integration with JSR-303 Bean Validation •  Declarative scheduling •  trigger abstraction and cron support •  Declarative caching •  in-memory, Ehcache, etc. |
  10. 10. Spring 3.x: Testing •  Embedded databases via <jdbc /> namespace •  @Configuration classes & @ActiveProfiles •  @WebAppConfiguration •  @ContextHierarchy •  Spring MVC Test framework |
  11. 11. Spring 3.x: Key Specifications •  JSR-330 (Dependency Injection for Java) •  @Inject, @Qualifier, Provider mechanism •  JSR-303 (Bean Validation 1.0) •  declarative constraints •  embedded validation engine |
  12. 12. Spring 3.x: Key Specifications •  JPA 2.0 •  persistence provider integration •  Spring transactions •  Servlet 3.0 •  web.xml-free deployment •  async request processing |
  13. 13. Typical Annotated Component |
  14. 14. Composable Stereotypes •  Combining meta-annotations on a custom stereotype •  Automatically detected: no configuration necessary! |
  15. 15. Configuration Classes |
  16. 16. Spring 4.0 Themes |
  17. 17. New Baseline •  Java SE 6+ •  Java EE 6+ (Servlet 3.0 focused, Servlet 2.5 compatible) •  All deprecated packages removed •  Many deprecated methods removed as well |
  18. 18. Third-party Libraries •  Minimum versions ~ mid 2010 now •  For example •  Hibernate 3.6+ •  Quartz 1.8+ •  Ehcache 2.1+ |
  19. 19. Java 8 Language & API Features •  Lambda expressions •  Method references •  JSR-310 Date and Time •  Repeatable annotations •  Parameter name discovery |
  20. 20. Groovy + Spring 4.0 •  A smooth out-of-the-box experience for Groovy-based Spring applications |
  21. 21. Groovy + Spring 4.0 •  AOP adaptations •  special handling of GroovyObject calls •  consider a Spring application with all components written in the Groovy language instead of Java |
  22. 22. Groovy + Spring 4.0 •  Groovy-based bean definitions •  formerly known as the Bean Builder in Grails •  now to live alongside Spring's configuration class model |
  23. 23. 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 be used for smart defaulting •  see Spring Boot J |
  24. 24. Conditional Bean Definitions •  @Conditional with programmatic Condition implementations •  can react to rich context (existing bean definitions, etc.) •  profile support now simply a ProfileCondition implementation class |
  25. 25. Annotation-based Components •  Custom annotations may override specific attributes of meta-annotations •  Purely convention-based •  use of same attribute name |
  26. 26. Annotation-based Components @MyTransactional(readOnly=true) @MySessionScope(scopedProxyMode=TARGET_CLASS) |
  27. 27. Lazy Resolution Proxies •  @Lazy on injection point •  Alternative to Provider<MyTargetType> |
  28. 28. Ordered Injection of Lists & Arrays •  Ordered/@Order on candidate beans •  Relative order within specific injection result |
  29. 29. DI and Generics •  Type matching based on full generic type •  e.g. MyRepository<Customer> •  Generic factory methods supported in XML config files •  Mockito, EasyMock, etc. |
  30. 30. spring-messaging •  New org.springframework.messaging module •  Extracted from Spring Integration •  Core message and channel abstractions |
  31. 31. WebSockets •  WebSocket endpoint model along the lines of Spring MVC •  JSR-356 but also covering SockJS and STOMP •  Endpoints using generic messaging patterns |
  32. 32. AsyncRestTemplate •  Analogous to existing RestTemplate •  Based on ListenableFuture return values |
  33. 33. Spring and Java EE |
  34. 34. Java EE Support (1/2) •  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 |
  35. 35. Java EE Support (2/2) •  Spring 3.1/3.2: strong Servlet 3.0 focus •  J2EE 1.4 (deprecated) – Java EE 6 •  Spring 4.0 introduces explicit Java EE 7 support •  Java EE 5 (with JPA 2.0 feature pack) – Java EE 7 |
  36. 36. Enterprise APIs (1/2) •  JMS 2.0 •  delivery delay, JMS 2.0 createSession() variants, etc. •  JTA 1.2 •  javax.transaction.Transactional annotation |
  37. 37. Enterprise APIs (2/2) •  JPA 2.1 •  unsynchronized persistence contexts •  Bean Validation 1.1 •  method parameter and return value constraints |
  38. 38. Spring and Java SE |
  39. 39. Java SE Support (1/2) •  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 |
  40. 40. Java SE Support (2/2) •  Spring 3.1/3.2: explicit Java 7 support •  JDK 5 – JDK 7 •  Spring 4.0 introduces explicit Java 8 support •  JDK 6 – JDK 8 |
  41. 41. Java 8 Programming Model |
  42. 42. 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 (!) |
  43. 43. IDE Support for Java 8 •  IntelliJ: available since IDEA 12, released in Dec 2012 •  Eclipse: announced for June 2014 (!) •  Spring Tool Suite: Eclipse-based beta support earlier |
  44. 44. Java 1.8 Bytecode Level •  Generated by -target 1.8 (compiler's default) •  Not accepted by ASM 4.x (Spring's bytecode parsing library) •  Spring Framework 4.0 comes with patched ASM 4.1 variant |
  45. 45. HashMap/HashSet Differences •  Different hash algorithms in use •  Leading to different hash iteration order •  Code shouldn't rely on such an order but sometimes does |
  46. 46. Java 8 Lambda Conventions •  Simple rule: interface with single method •  •  •  •  typically callback interfaces for example: Runnable, Callable formerly “single abstract method” (SAM) types now “functional interfaces” |
  47. 47. Lambda + Spring = Natural Fit •  Many Spring APIs are candidates for lambdas •  by naturally following the lambda interface conventions |
  48. 48. Lambdas with JMS APIs •  JmsTemplate + MessageCreator: •  Message createMessage(Session session) throws JMSException |
  49. 49. Lambdas with Tx APIs •  TransactionTemplate + TransactionCallback: •  Object doInTransaction(TransactionStatus status) |
  50. 50. Lambdas with JDBC APIs •  JdbcTemplate + RowMapper: •  Object mapRow(ResultSet rs, int rowNum) throws SQLException |
  51. 51. Lambdas with JdbcTemplate #1 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))); |
  52. 52. Lambdas with JdbcTemplate #2 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)); }); |
  53. 53. Method References (1/2) 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, "test"); }, this::mapPerson); } |
  54. 54. Method References (2/2) private Person mapPerson(ResultSet rs, int rowNum) throws SQLException { return new Person(rs.getString(1), rs.getInt(2)); } |
  55. 55. 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; |
  56. 56. 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() { /* ... */ } |
  57. 57. Parameter Name Discovery (1/2) •  Java 8 defines a Parameter reflection type for methods •  application sources to be compiled with -parameters |
  58. 58. Parameter Name Discovery (2/2) •  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) |
  59. 59. In Closing… |
  60. 60. Roadmap •  Spring Framework 4.0 RC1: end of October •  Spring Framework 4.0 RC2: mid November •  Spring Framework 4.0 GA: end of 2013 |
  61. 61. Upgrade Considerations •  Spring 3.2 does not support 1.8 bytecode level •  upgrade to Spring 4.0 to enable Java 8 language features •  Spring Framework 4.0 still compatible with JDK 6 and 7 •  Spring Framework 3.2 is in maintenance mode |
  62. 62. Acknowledgements Special thanks to Spring Framework project lead Juergen Hoeller for permitting reuse of his content. |
  63. 63. Spring Resources (1/2) •  Spring Framework •  http://projects.spring.io/spring-framework •  Spring Forums •  http://forum.spring.io |
  64. 64. Spring Resources (2/2) •  Spring JIRA •  https://jira.springsource.org •  Spring on GitHub •  https://github.com/spring-projects/spring-framework |
  65. 65. Blogs •  Swiftmind Blog •  http://www.swiftmind.com/blog •  Spring Blog •  http://spring.io/blog |
  66. 66. Thanks for your attention! @sam_brannen sam.brannen@swiftmind.com slideshare.net/sbrannen www. .com

×