BeJUG - Spring 3 talk
Upcoming SlideShare
Loading in...5
×
 

BeJUG - Spring 3 talk

on

  • 3,683 views

 

Statistics

Views

Total Views
3,683
Views on SlideShare
3,341
Embed Views
342

Actions

Likes
4
Downloads
123
Comments
1

7 Embeds 342

http://www.bejug.org 163
http://bubbl.dshaw.com 140
http://www.slideshare.net 16
http://tumble.dshaw.com 10
http://www.bejug.be 7
http://dshaw.com 4
http://devoxx.be 2
More...

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

BeJUG - Spring 3 talk BeJUG - Spring 3 talk Presentation Transcript

  • Spring Framework 3.0 Alef Arendsen Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • Agenda • Configuration options in 1.0, 2.0, 2.5 and 3.0 • Introduction of REST support in Spring MVC • Migration of OXM from WS to Spring Framework • Introduction of expression language support • Other features and considerations for Spring 3.0 2 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • Agenda • Configuration options in 1.0, 2.0, 2.5 and 3.0 • Introduction of REST support in Spring MVC • Migration of OXM from WS to Spring Framework • Introduction of expression language support • Other features and considerations for Spring 3.0 3 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • Spring 1.0 <beans/> schema <?xml version=quot;1.0quot; encoding=quot;UTF-8quot;?> <beans xmlns=quot;http://www.springframework.org/schema/beansquot; xmlns:xsi=quot;http://www.w3.org/2001/XMLSchema-instancequot; xsi:schemaLocation=quot;...quot;> <bean id=quot;clinicquot; class=quot;org.springframework.samples.petclinic.JdbcClinicquot;> <constructor-arg ref=quot;dataSourcequot;/> </bean> </beans> 4 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • Spring 2.0 schema support <?xml version=quot;1.0quot; encoding=quot;UTF-8quot;?> <beans xmlns=quot;http://www.springframework.org/schema/beansquot; xmlns:xsi=quot;http://www.w3.org/2001/XMLSchema-instancequot; xmlns:tx=quot;http://www.springframework.org/schema/txquot; xsi:schemaLocation=quot;...quot;> <tx:annotation-driven base-package=quot;org.springframework.samples.petclinicquot;/> </beans> 5 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • Spring 2.5 annotations @Transactional @Repository public class HibernateClinic implements Clinic { private SessionFactory sessionFactory; @Autowired public HibernateClinic( SessionFactory sessionFactory) { this.sessionFactory = sessionFactory; } } 6 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • Component scanning <?xml version=quot;1.0quot; encoding=quot;UTF-8quot;?> <beans xmlns=quot;http://www.springframework.org/schema/beansquot; xmlns:xsi=quot;http://www.w3.org/2001/XMLSchema-instancequot; xmlns:context=quot;http://www.springframework.org/schema/contextquot; xsi:schemaLocation=quot;...quot;> <context:component-scan base-package=quot;org.springframework.samples.petclinicquot;/> </beans> 7 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • @Controller for Spring MVC @Controller public class ClinicController { private final Clinic clinic; @Autowired public ClinicController(Clinic clinic) { this.clinic = clinic; } ... } 8 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • @RequestMapping methods @Controller public class ClinicController { ... @RequestMapping(quot;/vetsquot;) public List<Vet> vets() { return clinic.getVets(); } } 9 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • Constantly simplifying • LoC for sample application PetClinic over time Spring 2.0 Spring 2.5 10 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • Spring as a foundation • Other technologies building on the Spring foundation •Spring Batch 2.0 (e.g. with @BatchComponent) •Spring Integration 1.0 (e.g. with @MessageEndpoint) •Spring Web Services (e.g. with @Endpoint) •... • Most projects feature annotation-based options as well as XML-based ones 11 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • Other portfolio example: Spring Integration 1.0 - dec08 • Relatively new project under the Spring Portfolio umbrella • Focuses on in-VM lightweight integration scenarios –asynchronous messaging in a single VM –with adapters for many formats to integrate with external systems (JMS, Email, File, et cetera) • Implement of the Patterns of Enterprise Application Integration (Hohpe et. al.) 12 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • @MessageEndpoint @MessageEndpoint public class OrderSplitter { @Splitter(inputChannel=quot;ordersquot;, outputChannel=quot;drinksquot;) public List<OrderItem> split(Order order) { return order.getItems(); } } 13 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • @MessageEndpoint <si:splitter input-channel=quot;ordersquot; output-channel=quot;drinksquot; ref=quot;orderSplitterquot; method=quot;splitquot; /> <bean id=quot;orderSplitterquot; class=quot;org.sfw.integration..xml.OrderSplitterquot;/> Look ma, no annotations! public class OrderSplitter { public List<OrderItem> split(Order order) { return order.getItems(); } } 14 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • New in Spring 3.0 • Previously available in a separate project (Spring JavaConfig) • Has been available in prototype form since early 2005 • Now promoted to the core Spring Framework 15 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • Spring 1.0 <beans/> schema <?xml version=quot;1.0quot; encoding=quot;UTF-8quot;?> <beans xmlns=quot;http://www.springframework.org/schema/beansquot; xmlns:xsi=quot;http://www.w3.org/2001/XMLSchema-instancequot; xsi:schemaLocation=quot;...quot;> <bean id=quot;clinicquot; class=quot;org.springframework.samples.petclinic.JdbcClinicquot;> <constructor-arg ref=quot;dataSourcequot;/> </bean> </beans> 16 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • JavaConfig in Action @Configuration public abstract class MyConfig { @Bean public Clinic clinic() { DataSource ds = dataSource(); return new JdbcClinic(ds); } One method per bean @Autowired public abstract DataSource dataSource(); } 17 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • Agenda • Configuration options in 1.0, 2.0, 2.5 and 3.0 • Introduction of REST support in Spring MVC • Migration of OXM from WS to Spring Framework • Introduction of expression language support • Other features and considerations for Spring 3.0 18 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • Summary of REST • (Ideally) stateless server architecture • Resources • Actions / operations on those resources • Representations 19 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • A practical example • http://bank.com/account/1234 • Represents the account resources –GET retrieves the account •GET to bank.com/account/1234 to retrieve –PUT creates or modifies a resource •Post to bank.com/account/1234 to create/update –POST creates a resource •Post to bank.com/account to create a new account –DELETE deletes a resources •DELETE to bank.com/account/1234 to delete or for example deactiveate / cancel 20 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • Summary of Spring REST • URI template support (client & controller) • Support for representations (HTML, XML, RSS, Atom, PDF, Excel, JSON) • Servlet Filter to PUT/DELETE support • Built on Spring MVC 21 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • Support for URI templates @Controller @RequestMapping(quot;/account/*quot;) public class AccountController { @RequestMapping(value=quot;/*/{id}quot;, method=RequestMethod.GET) public Account get(@PathVariable long id) { // retrieve and return account } } Handles URL: http://bank.com/account/1234 22 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • Representations • Neatly laid-out support for several representations of your data: –HTML (e.g. through FreeMarker or JSPs) –PDF and Excel (POI, JExcelApi, iText) –JSON, RSS, Atom –XML • Support for changing the representation based on extension or the accept-header 23 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • Support for PUT and DELETE • Most browsers don’t support PUT / DELETE • So what about the following: @RequestMapping(value=quot;/*/{id}quot;, method=RequestMethod.DELETE) public void delete(@PathVariable long id) { // delete account } 24 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • Support for PUT and DELETE • Most browsers don’t support PUT / DELETE • So what about the following: @RequestMapping(value=quot;/*/{id}quot;, method=RequestMethod.DELETE) public void delete(@PathVariable long id) { // delete account } • Support for PUT and DELETE is added through a special ServletFilter (and in HTML for example using a hidden input field) 25 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • Agenda • Recap of Spring 2.5 configuration options and @MVC • Introduction of REST support in Spring MVC • Migration of OXM to Spring Framework • Introduction of expression language support • Other features and considerations for Spring 3.0 26 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • Object-XML mapping abstraction in Spring • Mapping objects to XML and vice versa through –XmlBeans, JiBX, Castor, JAXB (2), XStream • Used to be part of Spring WS • Useful for REST purposes as well • Moved to core Spring Framework as of 3.0 27 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • Interfaces for marshalling and unmarshalling public interface Marshaller { public void marshal(Object graph, Result result) throws XmlMappingException, IOException; } public interface Unmarshaller { public Object unmarshal(Source source) throws XmlMappingException, IOException; } 28 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • Usages throughout portfolio • JMS (MarshallingMessageConverter • MVC (MarshallingView) • Batch • ... 29 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • Agenda • Recap of Spring 2.5 configuration options and @MVC • Introduction of REST support in Spring MVC • Migration of OXM from WS to Spring Framework • Introduction of expression language support • Other features and considerations for Spring 3.0 30 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • Property externalization in 2.5 • Traditionally using <bean id=quot;dataSourcequot; class=quot;org.apache.commons.dbcp.BasicDataSourcequot; destroy-method=quot;closequot;> <property name=quot;driverClassNamequot; value=quot;${driver}quot;/> <property name=quot;urlquot; value=quot;${url}quot;/> <property name=quot;usernanequot; value=quot;${username}quot;/> <property name=quot;passwordquot; value=quot;${passwordquot;/> </bean> <context:property-placeholder location=quot;/WEB-INF/jdbc.propertiesquot;/> 31 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • Drawbacks of this approach • It only supports properties • The replacement is done at initialization time »Not at bean creation time • It doesn’t support conditionals or other constructs • It’s not very extensible for other frameworks 32 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • Introducing expressions • Spring 3.0 will include full support for the unified expression language • The replacement is done when the bean is created (and not when reading the configuration) 33 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • Introducing expressions • Spring 3.0 will include full support for the unified expression language • The replacement is done when the bean is created (and not when reading the configuration) <bean id=quot;dataSourcequot; class=quot;org.apache.commons.dbcp.BasicDataSourcequot; destroy-method=quot;closequot; scope=”prototype”> ... <property name=quot;urlquot; value=quot;${systemProperties.url}quot;/> </bean> 34 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • Using expressions in other parts of the portfolio • An extensible expression language • Will be used by other frameworks –Security (example below) –Integration / JMS (e.g. dynamic queue names) –Et cetera @PreAuthorize(quot;hasRole('ROLE_SUPERVISOR') or quot; + quot;hasRole('ROLE_TELLER') and quot; + quot;(#account.balance + #amount >= -#account.overdraft)quot; ) public void post(Account account, double amount); 35 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • Agenda • Recap of Spring 2.5 configuration options and @MVC • Introduction of REST support in Spring MVC • Migration of OXM from WS to Spring Framework • Introduction of expression language support • Other features and considerations for Spring 3.0 36 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • Backwards compatibility • Spring 3.0 will deprecate / remove various things •Traditional Spring MVC controller hierarchy (??) •Commons Attributes support •Traditional TopLink support •Traditional JUnit 3.8 class hierarchy • 95% backwards compatible with regards to APIs • 99% backwards compatible in the programming model 37 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • Roadmap • Spring 3.0 M1 released in December • Spring 3.0 M2 to be released any time now • Further Milestones later this quarter • Spring 3.0 RC and release Q2 2009 • More information on what features are included in which milestones: http://jira.springframework.org 38 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • Questions? Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.