BeJUG - Spring 3 talk

2,158 views

Published on

Published in: Technology
1 Comment
5 Likes
Statistics
Notes
No Downloads
Views
Total views
2,158
On SlideShare
0
From Embeds
0
Number of Embeds
366
Actions
Shares
0
Downloads
126
Comments
1
Likes
5
Embeds 0
No embeds

No notes for slide

BeJUG - Spring 3 talk

  1. 1. Spring Framework 3.0 Alef Arendsen Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  2. 2. 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.
  3. 3. 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.
  4. 4. 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.
  5. 5. 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.
  6. 6. 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.
  7. 7. 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.
  8. 8. @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.
  9. 9. @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.
  10. 10. 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.
  11. 11. 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.
  12. 12. 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.
  13. 13. @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.
  14. 14. @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.
  15. 15. 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.
  16. 16. 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.
  17. 17. 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.
  18. 18. 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.
  19. 19. 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.
  20. 20. 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.
  21. 21. 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.
  22. 22. 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.
  23. 23. 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.
  24. 24. 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.
  25. 25. 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.
  26. 26. 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.
  27. 27. 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.
  28. 28. 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.
  29. 29. Usages throughout portfolio • JMS (MarshallingMessageConverter • MVC (MarshallingView) • Batch • ... 29 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  30. 30. 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.
  31. 31. 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.
  32. 32. 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.
  33. 33. 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.
  34. 34. 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.
  35. 35. 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.
  36. 36. 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.
  37. 37. 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.
  38. 38. 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.
  39. 39. Questions? Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.

×