Spring Framework 3.

0
The Next Generation

Jürgen Höller
VP & Distinguished Engineer SpringSource

Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited.

Agenda
•  Quick Review: Spring 2.5 •  Spring 3.0 Themes and Features •  Spring 3.0 Roadmap

Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited.

2

Spring Framework 2.5
•  Comprehensive support for annotation-based configuration
–  @Autowired
•  with optional @Qualifier or custom qualifier

–  @Transactional –  @Service, @Repository, @Controller

•  Common Java EE 5 annotations supported too
–  –  –  –  @PostConstruct, @PreDestroy @PersistenceContext, @PersistenceUnit @Resource, @EJB, @WebServiceRef @TransactionAttribute

Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited.

3

. Copying.Annotated Bean Component @Service public class RewardNetworkService implements RewardNetwork { @Autowired public RewardNetworkService(AccountRepository ar) { … } @Transactional public RewardConfirmation rewardAccountFor(Dining d) { … } 4 } Copyright 2009 SpringSource. publishing or distributing without express written permission is prohibited.

etc --> Copyright 2009 SpringSource.myapp. publishing or distributing without express written permission is prohibited. Copying. DataSource.Minimal XML Bean Definitions <!– Activating annotation-based configuration --> <context:annotation-config/> <bean class=”com.RewardNetworkImpl”/> <bean class=”com. 5 .JdbcAccountRepository” /> <!– Plus shared infrastructure configuration beans: PlatformTransactionManager.rewards.rewards.myapp.

class) @ContextConfiguration public class RewardSystemIntegrationTests { @Autowired private RewardNetwork rewardNetwork. publishing or distributing without express written permission is prohibited. Copying.Test Context Framework @RunWith(SpringJUnit4ClassRunner. 6 . @Test @Transactional public void testRewardAccountForDining() { // test in transaction with auto-rollback } } Copyright 2009 SpringSource.

deleteBook(bookId).@MVC Controller Style @Controller public class MyController { private final MyService myService. } } Copyright 2009 SpringSource. @Autowired public MyController(MyService myService) { this. } @RequestMapping("/removeBook") public String removeBook(@RequestParam("book") String bookId) { this.myService = myService. 7 .myService. publishing or distributing without express written permission is prohibited. return "redirect:myBooks". Copying.

0. publishing or distributing without express written permission is prohibited.0 Themes •  Java 5+ foundation –  Unified EL++ •  Spring Expression Language –  and other Spring @MVC additions –  Hibernate Validator. etc •  Early support for Java EE 6 –  action/event/resource request mappings Copyright 2009 SpringSource. Copying.Spring 3.0. 8 . JSR 303 –  compatible with J2EE 1. JPA 2.4 and Java EE 5 •  Comprehensive REST support •  Declarative model validation •  Support for Portlet 2.0 –  JSF 2.

etc –  no spring.jar.New Project Layout •  Framework modules revised –  now managed in Maven style –  one source tree per module jar •  spring-beans.0 –  –  –  –  Ivy-based "Spring Build" system consistent deployment procedure consistent dependency management consistent generation of OSGi manifests Copyright 2009 SpringSource.jar.jar anymore! •  Built with new Spring build system as known from Spring Web Flow 2. spring-aop. 9 . publishing or distributing without express written permission is prohibited. Copying.

publishing or distributing without express written permission is prohibited.util. . Class<T> requiredType) –  Map<String.Core APIs updated for Java 5 •  BeanFactory interface returns typed bean instances as far as possible –  T getBean(String name.Executor now –  extended AsyncTaskExecutor supports standard Callables with Futures •  New Java 5 based converter API and SPI –  stateless ConversionService and Converters –  superseding standard JDK PropertyEditors •  Typed ApplicationListener<E> 10 Copyright 2009 SpringSource. Copying.concurrent. T> getBeansOfType(Class<T> type) •  Spring's TaskExecutor interface extends java.

EL in Bean Definitions <bean class="mycompany. Copying.databaseName}”/> <property name="keyGenerator"
 value="“#{strategyBean. publishing or distributing without express written permission is prohibited. 11 .RewardsTestDatabase"> <property name="databaseName"
 value="“#{systemProperties.databaseKeyGenerator}”/> </bean> Copyright 2009 SpringSource.

Copying.databaseName}”) public void setDatabaseName(String dbName) { … } @Value(“#{strategyBean. publishing or distributing without express written permission is prohibited.EL in Component Annotations @Repository public class RewardsTestDatabase { @Value(“#{systemProperties. 12 .databaseKeyGenerator}”) public void setKeyGenerator(KeyGenerator kg) { … } } Copyright 2009 SpringSource.

13 .0's expression support –  pluggable and customizable •  Compatible with Unified EL but significantly more powerful –  navigating bean properties.springframework.0 –  package org. Copying.Powerful Spring EL Parser •  Custom expression parser implementation shipped as part of Spring 3. publishing or distributing without express written permission is prohibited. maps. etc –  method invocations –  construction of value objects Copyright 2009 SpringSource.expression –  next-generation expression engine •  inspired by Spring Web Flow 2.

14 .g. Copying. for step scope in Spring Batch Copyright 2009 SpringSource. "systemEnvironment" •  global platform context –  access to all Spring-defined beans by name •  similar to managed beans in JSF expressions –  extensible through Scope SPI •  e. "systemProperties".EL Context Attributes •  Example showed access to EL attributes –  "systemProperties". publishing or distributing without express written permission is prohibited. depending on runtime context –  e.g. "strategyBean" –  implicit references in expressions •  Implicit attributes to be exposed by default.

publishing or distributing without express written permission is prohibited.Web Context Attributes •  Implicit web-specific attributes to be exposed by default as well –  –  –  –  "contextProperties": web. Copying. "facesContext".xml init-params "contextAttributes": ServletContext attributes "request": current Servlet/PortletRequest "session": current Http/PortletSession •  Exposure of all implicit JSF objects when running within a JSF request context –  "param". "initParam". 15 . etc –  full compatibility with JSF managed bean facility Copyright 2009 SpringSource.

publishing or distributing without express written permission is prohibited.g. Jersey) –  using the JAX-RS component model to build programmatic resource endpoints Copyright 2009 SpringSource.REST Support •  Spring MVC to provide first-class support for REST-style mappings –  extraction of URI template parameters –  content negotiation in view resolver •  Goal: native REST support within Spring MVC. Copying. 16 . for UI as well as non-UI usage –  in natural MVC style •  Alternative: using JAX-RS through integrated JAX-RS provider (e.

rewardsAdminService.com/rewards/12345 @RequestMapping(value = "/rewards/{id}". Copying.@PathVariable http://rewarddining.REST in MVC . } Copyright 2009 SpringSource. method = GET) public Reward reward(@PathVariable("id") long id) { return this.findReward(id). publishing or distributing without express written permission is prohibited. 17 .

18 .com/accounts/1.json •  XML GET http://rewarddining.com/accounts/1.com/accounts/1 accepts application/atom+xml GET http://rewarddining. publishing or distributing without express written permission is prohibited.com/accounts/1.xml •  ATOM GET http://rewarddining. Copying.com/accounts/1 accepts application/json GET http://rewarddining.atom Copyright 2009 SpringSource.com/accounts/1 accepts application/xml GET http://rewarddining.Different Representations •  JSON GET http://rewarddining.


 @CookieValue("language") String langId) { .. 19 . Copying. publishing or distributing without express written permission is prohibited..Common @MVC Refinements •  More options for handler method parameters –  –  –  –  in addition to @RequestParam and @PathVariable @RequestHeader: access to request headers @CookieValue: HTTP cookie access supported for Servlet MVC and Portlet MVC @RequestMapping("/show") public Reward show(@RequestHeader("region") long regionId. } Copyright 2009 SpringSource.

Model Validation public class Reward { @NotNull @Past private Date transactionDate. Copying. 20 . } In view: <form:input path="transactionDate"> •  Same metadata can be used for persisting. etc •  Spring: to be supported for MVC data binding •  JSR-303 "Bean Validation" as the common ground Copyright 2009 SpringSource. publishing or distributing without express written permission is prohibited. rendering.

0: major new capabilities –  –  –  –  explicit action name concept for dispatching resource requests for servlet-style serving events for inter-portlet communication portlet filters analogous to servlet filters •  Spring's Portlet MVC 3. @EventMapping –  specializations of Spring's @RequestMapping •  supporting action names. 21 . window states. @RenderMapping.Portlet 2. etc Copyright 2009 SpringSource. publishing or distributing without express written permission is prohibited. @ResourceMapping.0 to support explicit mapping annotations –  @ActionMapping. Copying.0 Support •  Portlet 2.

Spring Portlet MVC 3.0 @Controller @RequestMapping("EDIT") public class MyPortletController { … @ActionMapping("delete") public void removeBook(@RequestParam("book") String bookId) { this. } @EventMapping("BookUpdate") public void updateBook(BookUpdateEvent bookUpdate) { // extract book entity data from event payload object this. } 22 Copyright 2009 SpringSource. Copying. publishing or distributing without express written permission is prohibited.deleteBook(bookId).updateBook(…). } .myService.myService.

Copying.Conversation Management •  Key problem: isolating concurrent windows in same browser –  shared HTTP session •  identified by shared browser cookie –  several independent conversations going on •  keeping independent state •  Generalized: conversation scope with shorter lifetime than session –  scope="conversation" •  on-demand scoping of conversational Spring beans •  MyFaces Orchestra style –  Spring Web Flow 3 to share common conversation management foundation with Spring MVC Copyright 2009 SpringSource. 23 . publishing or distributing without express written permission is prohibited.

Copying. 24 .Scoped Bean Serializability •  Problem with Spring 2. publishing or distributing without express written permission is prohibited.5: serializability of session and conversation objects –  when referencing shared service objects via Spring dependency injection •  and not marking them as transient –  typical situation: scoped bean instance holds on to DataSource or the like •  DataSource reference is not serializable •  -> whole bean not serializable •  Solution: proxies that reobtain references on deserialization –  from current Spring WebApplicationContext Copyright 2009 SpringSource.

Scheduling Enhancements •  Spring 3.util.concurrent support •  prepared for JSR-236 "Concurrency Utilities for Java EE" –  TaskScheduler interface with Triggers •  including cron expression triggers –  @Async annotation for asynchronous user methods •  @Scheduled for cron-triggered methods •  XML scheduling namespace –  cron expressions with method references –  convenient executor service setup Copyright 2009 SpringSource. Copying. 25 .0 introduces a major overhaul of the scheduling package –  extended java. publishing or distributing without express written permission is prohibited.

0 (waiting for GlassFish 3 and Tomcat 7) –  JSR-236 "Concurrency Utilities for Java EE" Copyright 2009 SpringSource. 26 . Copying.0 and Java EE 6 •  Early Java EE 6 API support in Spring 3.2: support for Java EE 6 platforms –  Servlet 3.Spring 3.4+ •  Spring 3.0 –  integration with JSF 2. publishing or distributing without express written permission is prohibited.0 •  full compatibility as managed bean facility –  integration with JPA 2.0 integration –  all embeddable on Tomcat 5. query timeouts. etc –  support for JSR-303 Bean Validation annotations •  through Hibernate Validator 4.5+ / J2EE 1.0 •  support for lock modes.

publishing or distributing without express written permission is prohibited. 27 .0 M3 features a revised binding and type conversion infrastructure –  including the capabilities of Spring Web Flow's binding –  stateless type converter objects with EL integration •  Spring 3. for SQL XML access •  Spring 3. Copying.0 M2 includes a revised version of the Object/XML Mapping (OXM) module –  known from Spring Web Services –  also useful e.g.0 M3 also includes the core functionality of Spring JavaConfig –  configuration classes defining managed beans –  common handling of annotated factory methods Copyright 2009 SpringSource.Portfolio Rearrangements •  Spring 3.

28 .x support •  Some deprecation: superseded features –  traditional MVC form controller hierarchy •  superseded by annotated controller style –  traditional JUnit 3.8 test class hierarchy •  superseded by test context framework –  several outdated helper classes Copyright 2009 SpringSource. publishing or distributing without express written permission is prohibited.Pruning & Deprecation in 3.0 •  Some pruning: removal of outdated features –  Commons Attributes support •  superseded by Java 5 annotations –  traditional TopLink API support •  in favor of JPA (EclipseLink) –  subclass-style Struts 1. Copying.

Copying. publishing or distributing without express written permission is prohibited.0 API anymore! Copyright 2009 SpringSource.5 Mission Continued •  Spring 3 continues Spring 2.5 –  100% compatibility of programming model –  95% compatibility of extension points –  all previously deprecated API to be removed •  Make sure you're not using outdated Spring 1.2 / 2.5's mission –  fully embracing Java 5 in the core Spring programming and configuration model –  now with even the core framework requiring Java 5 •  all framework classes using Java 5 language syntax •  Backwards compatibility with Spring 2.Spring 2. 29 .

30 . Copying.Spring 3.5 on Java 5+ –  enabling a smooth migration path Copyright 2009 SpringSource.0 significantly extends and refines annotated web controllers –  RESTful URI mappings –  annotation-based model validation •  Spring 3.0 embraces REST and EL –  full-scale REST support –  broad Unified EL++ support in the core •  Spring 3. publishing or distributing without express written permission is prohibited.0 remains backwards compatible with Spring 2.0 Summary •  Spring 3.

Master your semester with Scribd & The New York Times

Special offer for students: Only $4.99/month.

Master your semester with Scribd & The New York Times

Cancel anytime.