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. Swiftmind: Areas of Expertise
• Spring Framework
• Java EE
• OSGi
• Agile Methodologies
• Software Engineering Best Practices
|
4. Swiftmind: How to find us
• Zurich, Switzerland
• Twitter: @swiftmind
• http://www.swiftmind.com
|
6. Agenda
• Spring 3.x in Review
• Themes in 4.0
• Java EE
• Java SE
• Spring 4 on Java 8
|
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. 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. 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. Spring 3.x: Testing
• Embedded databases via <jdbc /> namespace
• @Configuration classes & @ActiveProfiles
• @WebAppConfiguration
• @ContextHierarchy
• Spring MVC Test framework
|
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
|
19. Java 8 Language & API Features
• Lambda expressions
• Method references
• JSR-310 Date and Time
• Repeatable annotations
• Parameter name discovery
|
20. Groovy + Spring 4.0
• A smooth out-of-the-box experience for
Groovy-based Spring applications
|
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. 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. 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. 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. Annotation-based Components
• Custom annotations may override specific
attributes of meta-annotations
• Purely convention-based
• use of same attribute name
|
28. Ordered Injection of Lists & Arrays
• Ordered/@Order on candidate beans
• Relative order within specific injection result
|
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.
|
31. WebSockets
• WebSocket endpoint model along the lines of
Spring MVC
• JSR-356 but also covering SockJS and STOMP
• Endpoints using generic messaging patterns
|
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. 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
|
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. 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. 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. 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. 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. Lambda + Spring = Natural Fit
• Many Spring APIs are candidates for lambdas
• by naturally following the lambda interface
conventions
|
50. Lambdas with JDBC APIs
• JdbcTemplate + RowMapper:
• Object mapRow(ResultSet rs, int rowNum) throws
SQLException
|
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. 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. 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. Method References (2/2)
private Person mapPerson(ResultSet rs, int rowNum)
throws SQLException {
return new Person(rs.getString(1), rs.getInt(2));
}
|
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;
|
57. Parameter Name Discovery (1/2)
• Java 8 defines a Parameter reflection type for methods
• application sources to be compiled with -parameters
|
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)
|
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. 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
|