Spring Framework 3.

0
The Next Generation

Jürgen Höller
VP & Distinguished Engineer SpringSource

Copyright 2008 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 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.

2

Spring Framework 2.5
• Comprehensive support for annotation-based configuration
– @Autowired (+ @Qualifier or custom qualifiers) – @Transactional – @Service, @Repository, @Controller

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

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

3

Annotated Bean Component
@Service public class RewardNetworkService implements RewardNetwork { @Autowired public RewardNetworkService(AccountRepository ar) { … } @Transactional public RewardConfirmation rewardAccountFor(Dining d) { … } }

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

4

Annotated DAO with Lifecycle
@Repository public class JdbcAccountRepository implements AccountRepository { @Autowired public JdbcAccountRepository(DataSource ds) { … } @PostConstruct public initCache() { … } @PreDestroy public cleanupCache() { … } }

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

5

Minimal XML Bean Definitions
<!– Activating annotation-based configuration --> <context:annotation-config/> <bean class=”com.myapp.rewards.RewardNetworkService”/> <bean class=”com.myapp.rewards.JdbcAccountRepository”/> <!– Plus shared infrastructure configuration beans: PlatformTransactionManager, DataSource, etc -->

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

6

Minimal XML Bootstrapping
<!-- Scans for @Components, @Services, etc to deploy --> <context:component-scan base-package=”com.myapp.rewards”/> <!– Plus shared infrastructure configuration beans: PlatformTransactionManager, DataSource, etc -->

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

7

Test Context Framework
@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration public class RewardSystemIntegrationTests { @Autowired private RewardNetwork rewardNetwork; @Test @Transactional public void testRewardAccountForDining() { // test in transaction with auto-rollback } }

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

8

Spring Servlet MVC 2.5
@Controller public class MyController { private final MyService myService; @Autowired public MyController(MyService myService) { this.myService = myService; } @RequestMapping("/removeBook") public String removeBook( @RequestParam("book") String bookId) { myService.deleteBook(bookId); return "redirect:myBooks"; } }

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

9

Spring Portlet MVC 2.5
@Controller @RequestMapping("EDIT") public class MyPortletController { private final MyService myService; @Autowired public MyPortletController(MyService myService) { this.myService = myService; } @RequestMapping(params = "action=delete") public void removeBook(@RequestParam("book") String bookId, ActionResponse response) { myService.deleteBook(bookId); response.setRenderParameter("action", "list"); } }

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

10

Spring 3.0 Themes
• Java 5+ foundation
– compatible with J2EE 1.4 and Java EE 5

• 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

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

11

EL in Bean Definitions

<bean class="mycompany.RewardsTestDatabase"> <property name="databaseName" value="“#{systemProperties.databaseName}”/> <property name="keyGenerator" value="“#{strategyBean.databaseKeyGenerator}”/> </bean>

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

12

EL in Component Annotations

@Repository public class RewardsTestDatabase { @Value(“#{systemProperties.databaseName}”) public void setDatabaseName(String dbName) { } @Value(“#{strategyBean.databaseKeyGenerator}”) public void setKeyGenerator(KeyGenerator kg) { … } }

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

13

Conversation Management
• Key problem: isolating concurrent windows in same browser
– shared HTTP session – several independent conversations going on

• Generalized: conversation scope with shorter lifetime than session
– scope="conversation" – Spring Web Flow providing sophisticated flow navigation management on top

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

14

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

• Alternative: using JAX-RS through integrated JAX-RS provider (e.g. Jersey)
– using the JAX-RS component model to build programmatic resource endpoints

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

15

REST in MVC - @UriVariable

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

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

16

Different Representations
• JSON
GET http://rewarddining.com/accounts/1 accepts application/json GET http://rewarddining.com/accounts/1.json

• XML
GET http://rewarddining.com/accounts/1 accepts application/xml GET http://rewarddining.com/accounts/1.xml

• ATOM
GET http://rewarddining.com/accounts/1 accepts application/atom+xml GET http://rewarddining.com/accounts/1.atom

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

17

Model Validation
public class Reward { @NotNull @ShortDate private Date transactionDate; } In view:
<form:input path="transactionDate">

• Same metadata can be used for persisting, rendering, etc • Hibernate Validator annotations supported • JSR 303 (Bean Validation) to be supported as well

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

18

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

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

19

Spring 2.5 Mission Continued
• Spring 3 continues Spring 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 API to use Java 5 language syntax

• Backwards compatibility with 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.0 API anymore!

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

20

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 extends 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

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

21

Spring 3.0 Roadmap
• Spring Framework 3.0 M1 to be released by the end of November
– new project layout – first cut of REST and EL support

• Spring Framework 3.0 RC1 scheduled for March 2009
– after two further milestones

• Spring Framework 3.0 final expected in April 2009
– depending on RC feedback

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

22

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

23

Sign up to vote on this title
UsefulNot useful