03-what s new in spring 3

Upload: qzejvdhwlqzzx

Post on 07-Apr-2018

217 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/3/2019 03-What s New in Spring 3

    1/35

    Whats new in

    Spring 3.0?Arjen PoutsmaSpringSource

  • 8/3/2019 03-What s New in Spring 3

    2/35

    SpringSource Confidential. Do not distribute without express permission

    About Me

    Fifteen years of experience in EnterpriseSoftware Development

    Development lead of Spring Web Services Developer on Spring 3

    Contributor to various Open Sourceframeworks: (XFire, Axis2, NEO, ...)

  • 8/3/2019 03-What s New in Spring 3

    3/35

    SpringSource Confidential. Do not distribute without express permission

    Themes

    Java 5+

    Spring Expression Language

    REST support Portlet 2.0

    Declarative model validation Early support for Java EE 6

  • 8/3/2019 03-What s New in Spring 3

    4/35

    Java 5+

  • 8/3/2019 03-What s New in Spring 3

    5/35

    SpringSource Confidential. Do not distribute without express permission5

    Generics

    publicinterface BeanFactory {

    T getBean(String name, Class requiredType);

    Map getBeansOfType(Class type);

    }

  • 8/3/2019 03-What s New in Spring 3

    6/35

    SpringSource Confidential. Do not distribute without express permission

    Rearrangements

    Objext/XML Mapping (OMX) module

    REST, SQL XML access Conversion infrastructure stateless Java 5+ type converters and

    formatters

    superseding PropertyEditors

  • 8/3/2019 03-What s New in Spring 3

    7/35SpringSource Confidential. Do not distribute without express permission

    Annotated Factory

    Methods

    Spring JavaConfig configuration classes

    annotated factory methods

  • 8/3/2019 03-What s New in Spring 3

    8/35SpringSource Confidential. Do not distribute without express permission

    @Configuration

    publicclass AppConfig{

    @Bean @Lazypublic RewardsService rewardsService() {

    RewardsServiceImpl service =

    new RewardsServiceImpl();

    service.setDataSource();

    return service;

    }

    }

  • 8/3/2019 03-What s New in Spring 3

    9/35SpringSource Confidential. Do not distribute without express permission

    Meta-Annotations

    @Service

    @Scope("request")

    @Transactional(rollbackFor=Exception.class)

    @Retention(RetentionPolicy.RUNTIME)

    public @interface MyService {}

    @MyService

    public class RewardsService {

    }

  • 8/3/2019 03-What s New in Spring 3

    10/35

    Expression Language

  • 8/3/2019 03-What s New in Spring 3

    11/35SpringSource Confidential. Do not distribute without express permission

    EL in Bean Definitions

  • 8/3/2019 03-What s New in Spring 3

    12/35SpringSource Confidential. Do not distribute without express permission

    EL in Component

    Annotations@Repository

    publicclass RewardsTestDatabase {

    @Value(#{systemProperties.databaseName})

    public voidsetDatabaseName(String dbName) { }

    @Value(#{strategyBean.databaseKeyGenerator})

    public voidsetKeyGenerator(KeyGenerator kg) { }

    }

  • 8/3/2019 03-What s New in Spring 3

    13/35SpringSource Confidential. Do not distribute without express permission

    Default Context

    Attributes Exposed by default

    "systemProperties", "systemEnvironment" access to all Spring-defined beans byname

    extensible through SPI Determined at runtime (not init-time)

  • 8/3/2019 03-What s New in Spring 3

    14/35SpringSource Confidential. Do not distribute without express permission

    Web Context

    Attributes Web-specific attributes:

    "contextParameters"

    "contextAttributes" "request"

    "session" JSF objects in a JSF request context

  • 8/3/2019 03-What s New in Spring 3

    15/35

    Web

  • 8/3/2019 03-What s New in Spring 3

    16/35

    SpringSource Confidential. Do not distribute without express permission

    URI Templates

    URI-like string, containing one or morevariable names

    Variables can be substituted for values tobecome a URI

    Helps to create nice, RESTful URLs

  • 8/3/2019 03-What s New in Spring 3

    17/35

    Examples

    URI Template Request Variables

    /hotels/{hotelId}/hotels/

    westindiplomathotelId=

    westindiplomat

    /hotels/{hotelId}/

    bookings

    /hotels/westindiplomat/

    bookings

    hotelId=

    westindiplomat

    /hotels/{hotelId}/bookings/{bookingId}

    /hotels/westindiplomat/bookings/21

    hotelId=westindiplomatbookingId=21

  • 8/3/2019 03-What s New in Spring 3

    18/35

    SpringSource Confidential. Do not distribute without express permission

    @PathVariable

    Spring 3.0 M1 introduced the@PathVariable annotation

    Allows you to use URI Templates in @MVC

  • 8/3/2019 03-What s New in Spring 3

    19/35

    SpringSource Confidential. Do not distribute without express permission

    @Controller@RequestMapping("/hotels/{hotel}")publicclass HotelsController {

    @RequestMapping

    publicvoidhandleHotel(@PathVariable("hotel") String hotel) { // ...

    }

    @RequestMapping("bookings/{booking}")

    publicvoidhandleBooking(@PathVariable("hotel") String hotel, @PathVariableint booking) { // ...

    }

    }

    Example

  • 8/3/2019 03-What s New in Spring 3

    20/35

    SpringSource Confidential. Do not distribute without express permission

    @Controller@RequestMapping("/hotels/{hotel}")publicclass HotelsController {

    @RequestMapping

    publicvoidhandleHotel(@PathVariable("hotel") String hotel) { // ...

    }

    @RequestMapping("bookings/{booking}")

    publicvoidhandleBooking(@PathVariable("hotel") String hotel, @PathVariableint booking) { // ...

    }

    }

    ExampleOptional

  • 8/3/2019 03-What s New in Spring 3

    21/35

    SpringSource Confidential. Do not distribute without express permission

    @Controller@RequestMapping("/hotels/{hotel}")publicclass HotelsController {

    @RequestMapping

    publicvoidhandleHotel(@PathVariable("hotel") String hotel) { // ...

    }

    @RequestMapping("bookings/{booking}")

    publicvoidhandleBooking(@PathVariable("hotel") String hotel, @PathVariableint booking) { // ...

    }

    }

    ExampleOptional

    Matches /hotels/42

  • 8/3/2019 03-What s New in Spring 3

    22/35

    SpringSource Confidential. Do not distribute without express permission

    @Controller@RequestMapping("/hotels/{hotel}")publicclass HotelsController {

    @RequestMapping

    publicvoidhandleHotel(@PathVariable("hotel") String hotel) { // ...

    }

    @RequestMapping("bookings/{booking}")

    publicvoidhandleBooking(@PathVariable("hotel") String hotel, @PathVariableint booking) { // ...

    }

    }

    ExampleOptional

    Matches /hotels/42/bookings/21

    Matches /hotels/42

  • 8/3/2019 03-What s New in Spring 3

    23/35

    SpringSource Confidential. Do not distribute without express permission

    Views

    Mime Type View

    application/xml MarshallingView

    application/atom+xml AbstractAtomFeedView

    application/rss+xml AbstractRssFeedView

    application/json MappingJacksonJsonView

  • 8/3/2019 03-What s New in Spring 3

    24/35

    SpringSource Confidential. Do not distribute without express permission

    Other Goodies

    HiddenHttpMethodFilter ShallowEtagHeaderFilter

    @RequestHeader, @RequestBody,

    @ResponseBody, @CookieValue

    http://blog.springsource.com/2009/03/08/rest-in-spring-3-mvc/

    http://blog.springsource.com/2009/03/08/rest-in-spring-3-mvc/http://blog.springsource.com/2009/03/08/rest-in-spring-3-mvc/http://blog.springsource.com/2009/03/08/rest-in-spring-3-mvc/
  • 8/3/2019 03-What s New in Spring 3

    25/35

    SpringSource Confidential. Do not distribute without express permission

    RestTemplate

    RestTemplate as core client-sidecomponent

    Similar to other templates in Spring JdbcTemplate

    JmsTemplate WebServiceTemplate

  • 8/3/2019 03-What s New in Spring 3

    26/35

    SpringSource Confidential. Do not distribute without express permission

    RestTemplate

    String uri = "http://example.com/hotels/{id}";template = new RestTemplate();HotelList result = template.getForObject(uri,HotelList.class, "1");

    Booking booking = // create booking objecturi = "http://example.com/hotels/{id}/bookings";Map vars = Collections.singletonMap("id", "1");URI location = template.postForLocation(uri, booking, vars);

    template.delete(location.toString());

    template.execute(uri, HttpMethod.GET,myRequestCallback,myResponseCallback);

    http://blog.springsource.com/2009/03/27/rest-in-spring-3-resttemplate/

    http://blog.springsource.com/2009/03/27/rest-in-spring-3-resttemplate/http://blog.springsource.com/2009/03/27/rest-in-spring-3-resttemplate/http://blog.springsource.com/2009/03/27/rest-in-spring-3-resttemplate/http://blog.springsource.com/2009/03/27/rest-in-spring-3-resttemplate/http://blog.springsource.com/2009/03/27/rest-in-spring-3-resttemplate/http://blog.springsource.com/2009/03/27/rest-in-spring-3-resttemplate/
  • 8/3/2019 03-What s New in Spring 3

    27/35

    SpringSource Confidential. Do not distribute without express permission

    Portlet 2.0 Support

    @Controller

    @RequestMapping("EDIT")

    public class MyPortletController {

    @ActionMapping("delete")

    public voidremoveBook(@RequestParam("book") String bookId) {

    this.myService.deleteBook(bookId);

    }

    @EventMapping("BookUpdate")

    public voidupdateBook(BookUpdateEvent bookUpdate) {

    // extract book entity data from event payload object

    this.myService.updateBook();

    }

    }

  • 8/3/2019 03-What s New in Spring 3

    28/35

    SpringSource Confidential. Do not distribute without express permission

    Declarative Validation

    Annotation-based

    Same metadata can be used for persisting,rendering, etc

    JSR-303 "Bean Validation" as the commonground

    Spring 3.x will fully support JSR-303 as itbecomes final

  • 8/3/2019 03-What s New in Spring 3

    29/35

    SpringSource Confidential. Do not distribute without express permission

    Declarative Validation

    Sam lepublicclass Reward {

    @NotNull

    @Past

    private Date transactionDate;

    }

  • 8/3/2019 03-What s New in Spring 3

    30/35

    Various

  • 8/3/2019 03-What s New in Spring 3

    31/35

    SpringSource Confidential. Do not distribute without express permission

    Spring 3.0 and Java EE 6

    Early Java EE 6 support in Spring 3.0

    JSF 2.0 JPA 2.0

    JSR-303 Bean Validation

    Spring 3.1: full support for Java EE 6

  • 8/3/2019 03-What s New in Spring 3

    32/35

    SpringSource Confidential. Do not distribute without express permission

    Pruning & Deprecation

    Pruned:

    Commons Attributessupport

    traditional TopLinkAPI support

    Deprecated:

    MVC controllerhierarchy

    JUnit 3.8 support

    Struts 1.x support

    several outdatedhelper classes

  • 8/3/2019 03-What s New in Spring 3

    33/35

    SpringSource Confidential. Do not distribute without express permission

    Other

    Scoped Bean Serializability

    reobtain references on deserialization

    Scheduling Enhancements@Async, cron-style triggers

    Backwards compatibile with Spring 2.5 100% programming model

    95% compatibility of extension points

  • 8/3/2019 03-What s New in Spring 3

    34/35

    SpringSource Confidential. Do not distribute without express permission

    Summary

    Java 5+

    Full-scale REST support Broad Unified EL++ support in the core

    Annotation-based model validation

    Remains backwards compatible

  • 8/3/2019 03-What s New in Spring 3

    35/35

    Roadmap

    3.0 RC1: September 2009 feature-complete and fully documented

    3.0 RC2: November 2009 3.0 GA: December 2009

    3.1: Q2 2010 already compatibility with Java EE 6

    support for conversations