Copying, publishing or distributing without express written permission is prohibited. 34 private String favoriteColor;.
Spring Update: Implications for the Advanced Developer Rod Johnson Founder, Spring CEO, 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
• Special emphasis: • What does this mean for best practice for advanced developers?
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 – @Component, @Service, @Repository, @Controller
• Common Java EE 5 annotations supported – – – –
@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(>
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
13
The @Component metaannotation • Meta-annotations • Annotations can annotate other annotations • Allow extensibility • Similar to Java inheritance
• Spring stereotypes • Concept introduced in Spring 2.0, but more stereotypes added later • Identify classes with a particular purpose • Help to build a strong semantic model of application • Not Spring-specific • Common identifiers for regular code Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
14
Spring stereotype annotations • @Service • Identifies a stateless service
• @Repository • Identifies a repository (DAO)
• @Aspect • @AspectJ aspect
• @Controller • Spring MVC controller
• Can define your own… • @Component
@Qualifier @Component public @interface Emea { }
• Meta-annotation • Annotate your own annotation with @Component and your classes get picked up by scanning Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
15
Component Scanning • Scans the classpath for annotated classes • Removes the need for XML definitions unless you want to need to do something you can’t do in annotations @Service public class DefaultAccountService { ...
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
16
Component Scan Usage • Use Spring core context namespace • Specify package(s) to pick up • Can coexist with XML bean definitions and namespaces
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
17
More advanced component scanning usage • Not limited to annotations • Can use type or other checks
• Highly customizable, as you expect from Spring • Can even work without using annotations
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
18
Component Scan Pros • No need for XML unless you need the greater sophistication it allows • Changes are picked up automatically • Great during development
• Works great with Annotation Driven Injection • picking up further dependencies with @Autowired
• Highly configurable
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
19
Component Scan Cons • Not a 100% solution • Can’t do everything with annotations
• Requires classes to be annotated • Need to take care not to scan an excessive number of classes, using Spring’s filtering mechanism • Don’t get the valuable application structure blueprints you get with XML configuration Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
20
Mix and Match • All Spring meta>