Вы находитесь на странице: 1из 25

Spring 3 .

0
The Next Generation

Jrgen Hller VP & Distinguished Engineer SpringSource


Submission no. 7440

AGENDA
> Spring 3.0 Themes Java 5 REST ex pression language annot at ed web cont rollers > Spring 3.0 Roadmap

Spring 3 .0 Themes
> Java 5+ foundation even stronger support for annotated components > Spring Expression Language Unified EL+ + > Comprehensive REST support and other Spring @MVC additions > Declarative model validation Hibernate Validator, JSR 303 > Support for Portlet 2.0 action/ event/ resource request mappings > Early support for Java EE 6 JSF 2.0, JPA 2.0, etc

Core APIs updated for Java 5


> BeanFactory interface returns typed bean instances as far as possible T getBean(String name, Class< T> requiredType) > Map< String, T> getBeansOfType(Class< T> type)

Spring's TaskExecutor interface ex tends java.util.concurrent.Ex ecutor now extended AsyncTaskEx ecutor supports standard Callables with Futures Typed ApplicationListener< E> ApplicationEventMulticaster detects declared event type and filters accordingly

>

Portfolio Rearrangements
> Spring 3.0 includes a revised version of the Object/ XML Mapping (OXM) module known from Spring Web Services > supported for REST- style payload conversion also useful e.g. for SQL XML access

Spring 3.0 features a revised binding and type conversion infrastructure including the capabilities of Spring Web Flow's binding stateless Java 5+ type converters with EL integration superseding standard JDK PropertyEditors

Annotated Factory Methods


> Spring 3.0 includes the core functionality of the Spring JavaConfig project configuration classes defining managed beans common handling of annotated factory methods

@Bean @Primary @Lazy public RewardsService rewardsService() { RewardsServiceImpl service = new RewardsServiceImpl(); service.setDataSource(); return service; }

Use of Meta- Annotations


> More powerful options for custom annotations combining meta- annotations e.g. on stereotype automatically detected (no configuration necessary!) @Service @Scope("request") @Transactional(rollbackFor=Exception.class) @Retention(RetentionPolicy.RUNTIME) public @interface MyService {} @MyService public class RewardsService { }

EL in Bean Definitions
<bean class="mycompany.RewardsTestDatabase"> <property name="databaseName" value="#{systemProperties.databaseName}/> <property name="keyGenerator" value="#{strategyBean.databaseKeyGenerator}/> </bean>

EL in Component Annotations
@Repository public class RewardsTestDatabase { @Value(#{systemProperties.databaseName}) public void setDatabaseName(String dbName) { } @Value(#{strategyBean.databaseKeyGenerator}) public void setKeyGenerator(KeyGenerator kg) { } }

10

EL Context Attributes
> Example showed access to EL attributes "systemProperties", "strategyBean" > implicit references in ex pressions

Implicit attributes to be ex posed by default, depending on runtime contex t e.g. "systemProperties", "systemEnvironment": global platform context access to all Spring- defined beans by name: similar to managed beans in JSF ex pressions extensible through Scope SPI: e.g. for step scope in Spring Batch

11

Web Context Attributes


> Implicit web- specific attributes to be exposed by default as well "contextParameters": web.x ml init- params > "contextAttributes": ServletContex t attributes "request": current Servlet/ PortletRequest "session": current Http/ PortletSession

Exposure of all implicit JSF objects when running within a JSF request contex t "param", "initParam", "facesContex t", etc full compatibility with JSF managed bean facility seamless move between JSF expressions and Spring ex pressions supporting JSF 1.2 as well as JSF 2.0

12

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, for UI as well as non- UI usage in natural MVC style first- class support for view rendering/ dispatching Alternative: using JAX- RS through integrated JAX- RS provider (e.g. Jersey) using the JAX- RS component model to build programmatic resource endpoints Spring integration available in all common JAX- RS providers already

>

>

13

REST in MVC - @PathVariable


http:/ / rewarddining.com/ rewards/ 12345
@RequestMapping(value = "/rewards/{id}", method = GET) public Reward reward(@PathVariable("id") long id) { return this.rewardsAdminService.findReward(id); }

14

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, @CookieValue("language") String langId) { ... }

15

Portlet 2 .0 Support
> Portlet 2.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.0 to support explicit mapping annotations @ActionMapping, @RenderMapping @ResourceMapping, @EventMapping specializations of Spring's @RequestMapping: supporting action names, window states, etc

16

Spring Portlet MVC 3 .0


@Controller @RequestMapping("EDIT") public class MyPortletController { @ActionMapping("delete") public void removeBook(@RequestParam("book") String bookId) { this.myService.deleteBook(bookId); } @EventMapping("BookUpdate") public void updateBook(BookUpdateEvent bookUpdate) { // extract book entity data from event payload object this.myService.updateBook(); } }

17

Model Validation
public class Reward { @NotNull @Past private Date transactionDate; }
In view:

<form:input path="transactionDate"> > > > Same metadata can be used for persisting, rendering, etc Spring 3.0: to be supported for MVC data binding JSR- 3 0 3 "Bean Validation" as the common ground standardized constraint annotations

18

Scoped Bean Serializability


> Problem with Spring 2.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 corresponding Spring ApplicationContex t similar to "scoped" proxies choice to be made per component: serializing state or reference?

>

19

Scheduling Enhancements
> Spring 3.0 introduces a major overhaul of the scheduling package extended java.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 ex ecutor and scheduler setup similar to jms namespace

20

Spring 3 .0 and Java EE 6


> Early Java EE 6 API support in Spring 3.0 integration with JSF 2 .0 : full compatibility as managed bean facility integration with JPA 2 .0 : support for lock modes, query timeouts, etc support for JSR- 3 0 3 Bean Validation annotations: through Hibernate Validator 4.0 integration all embeddable on Tomcat 5.5+ / J2EE 1.4+ Spring 3.x : support for Java EE 6 platforms Servlet 3.0: waiting for GlassFish 3 and Tomcat 7 JSR- 236 "Concurrency Utilities for Java EE"

>

21

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.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 contex t framework

22

Spring 2 .5 Mission Continued


> Spring 3 continues Spring 2.5's mission fully embracing Java 5 in the 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.5 100% compatibility of programming model 95% compatibility of ex tension points All previously deprecated API to be removed Make sure you're not using outdated Spring 1.2 / 2.0 API anymore!

23

Spring 3 .0 Summary
> Spring 3.0 embraces REST and EL full- scale REST support broad Unified EL+ + support in the core

> Spring 3.0 significantly ex tends and refines annotated web controllers RESTful URI mappings annotation- based model validation

> Spring 3.0 remains backwards compatible with Spring 2.5 on Java 5+ enabling a smooth migration path

24

Spring 3 .0 Roadmap
> Spring Framework 3.0 RC1 scheduled for July 2009 feature- complete and fully documented > Spring Framework 3.0 GA ex pected in August 2009 depending on RC feedback > Spring Framework 3.1 ex pected in early 2010 full compatibility with Java EE 6 platforms first- class support for conversation management

Jrgen Hller

www.springsource.com

SpringSource juergen.hoeller@springsource.com

Вам также может понравиться