marsjug - spring 3.0
DESCRIPTION
Spring 3.0 presentation at MarsJUGTRANSCRIPT
![Page 1: MarsJUG - Spring 3.0](https://reader033.vdocuments.mx/reader033/viewer/2022050721/55660b63d8b42aa6628b50ee/html5/thumbnails/1.jpg)
Spring 3.0Gildas Cuisinier
vendredi 19 février 2010
![Page 2: MarsJUG - Spring 3.0](https://reader033.vdocuments.mx/reader033/viewer/2022050721/55660b63d8b42aa6628b50ee/html5/thumbnails/2.jpg)
Gildas Cuisinier
Consultant Java depuis 3 ansGam Consult Luxembourg
Certifié Spring
Responsable Spring @ Developpez.com
Article, FAQ, Forum, Compte rendu
Relecteur technique
2vendredi 19 février 2010
![Page 3: MarsJUG - Spring 3.0](https://reader033.vdocuments.mx/reader033/viewer/2022050721/55660b63d8b42aa6628b50ee/html5/thumbnails/3.jpg)
Agenda
RetrospectiveSpring 3.0Spring et JEE 6
3vendredi 19 février 2010
![Page 4: MarsJUG - Spring 3.0](https://reader033.vdocuments.mx/reader033/viewer/2022050721/55660b63d8b42aa6628b50ee/html5/thumbnails/4.jpg)
Retrospective
vendredi 19 février 2010
![Page 5: MarsJUG - Spring 3.0](https://reader033.vdocuments.mx/reader033/viewer/2022050721/55660b63d8b42aa6628b50ee/html5/thumbnails/5.jpg)
Avant Spring
EJB 2Modèle complexe
Difficile à tester
5vendredi 19 février 2010
![Page 6: MarsJUG - Spring 3.0](https://reader033.vdocuments.mx/reader033/viewer/2022050721/55660b63d8b42aa6628b50ee/html5/thumbnails/6.jpg)
Spring 1.0
Mars 2004Fonctionnalités
Inversion du contrôle
Programmation Orienté Aspect (AOP)
Support de Jdbc, Hibernate, JDO
Framework Web
6vendredi 19 février 2010
![Page 7: MarsJUG - Spring 3.0](https://reader033.vdocuments.mx/reader033/viewer/2022050721/55660b63d8b42aa6628b50ee/html5/thumbnails/7.jpg)
Instanciation
7
Dépendance directeDifficile à tester
vendredi 19 février 2010
![Page 8: MarsJUG - Spring 3.0](https://reader033.vdocuments.mx/reader033/viewer/2022050721/55660b63d8b42aa6628b50ee/html5/thumbnails/8.jpg)
Registre
8
vendredi 19 février 2010
![Page 9: MarsJUG - Spring 3.0](https://reader033.vdocuments.mx/reader033/viewer/2022050721/55660b63d8b42aa6628b50ee/html5/thumbnails/9.jpg)
IoC : Injection de dépendances
9
Instancie
Instancie
InstancieInstancie
Injecte InstanceB
vendredi 19 février 2010
![Page 10: MarsJUG - Spring 3.0](https://reader033.vdocuments.mx/reader033/viewer/2022050721/55660b63d8b42aa6628b50ee/html5/thumbnails/10.jpg)
IoC : Avantages
10
POJODépendance uniquement sur les contratsPlus simple à tester
vendredi 19 février 2010
![Page 11: MarsJUG - Spring 3.0](https://reader033.vdocuments.mx/reader033/viewer/2022050721/55660b63d8b42aa6628b50ee/html5/thumbnails/11.jpg)
Spring 1.0
Configuration xml, basée sur une DTD
Un seul tag : <bean>
Possibilité de métadonnées sur les classes
Basé sur Xdoclet
vendredi 19 février 2010
![Page 12: MarsJUG - Spring 3.0](https://reader033.vdocuments.mx/reader033/viewer/2022050721/55660b63d8b42aa6628b50ee/html5/thumbnails/12.jpg)
Spring 1.2
Mai 2005Toujours basé sur une DTD
Alias, import
Premier support du JDK 5 !@Transactional, …
vendredi 19 février 2010
![Page 13: MarsJUG - Spring 3.0](https://reader033.vdocuments.mx/reader033/viewer/2022050721/55660b63d8b42aa6628b50ee/html5/thumbnails/13.jpg)
Spring 2.0
Octobre 2006Simplification de la configuration XML
Basé sur XML Schema
Namespaces dédiés
JEE, Transaction, AOP, Lang, Util
Scope
Annotations AspectJ13
vendredi 19 février 2010
![Page 14: MarsJUG - Spring 3.0](https://reader033.vdocuments.mx/reader033/viewer/2022050721/55660b63d8b42aa6628b50ee/html5/thumbnails/14.jpg)
Spring 2.5
Novembre 2007Nouveaux namespaces :
JMS
Context
Annotations Spring : IoC, Tests, Web
Standard JEE
Toujours compatible JDK 1.4 14
vendredi 19 février 2010
![Page 15: MarsJUG - Spring 3.0](https://reader033.vdocuments.mx/reader033/viewer/2022050721/55660b63d8b42aa6628b50ee/html5/thumbnails/15.jpg)
Spring 3.0
vendredi 19 février 2010
![Page 16: MarsJUG - Spring 3.0](https://reader033.vdocuments.mx/reader033/viewer/2022050721/55660b63d8b42aa6628b50ee/html5/thumbnails/16.jpg)
Spring 3.0
Supports, dépréciations et suppressionsNouveautés de Spring 3
Rest, Expression Languages, namespaces
Spring 3.1
16vendredi 19 février 2010
![Page 17: MarsJUG - Spring 3.0](https://reader033.vdocuments.mx/reader033/viewer/2022050721/55660b63d8b42aa6628b50ee/html5/thumbnails/17.jpg)
Java 5 - ApplicationContext
17
SpeakerRepository repository = context.getBean(SpeakerRepository.class);
<T> T getBean(Class<T> requiredType) throws BeansException;
Pas de casting
vendredi 19 février 2010
![Page 18: MarsJUG - Spring 3.0](https://reader033.vdocuments.mx/reader033/viewer/2022050721/55660b63d8b42aa6628b50ee/html5/thumbnails/18.jpg)
Java 5 - RowMapper
18
private class SpeakerMapper implements RowMapper<Speaker> {
public Speaker mapRow(ResultSet rs, int rowNum) throws SQLException { return SpeakerBuilder.SpeakerWith() .id(rs.getInt(1)) .firstName( rs.getString(2)) .lastName(rs.getString(3)) .email(rs.getString(4)) .birthday(rs.getDate(5)) .build(); } }
vendredi 19 février 2010
![Page 19: MarsJUG - Spring 3.0](https://reader033.vdocuments.mx/reader033/viewer/2022050721/55660b63d8b42aa6628b50ee/html5/thumbnails/19.jpg)
Java 5 - Varargs
19
public Integer save(Speaker speaker) { return template.update("insert into speakers values(null, ?,?,?,?)", speaker.getFirstName(), speaker.getLastName(), speaker.getEmail(), speaker.getBirthday()); }
Avantpublic Integer saveOld(Speaker speaker) { return template.update("insert into speakers values(null, ?,?,?,?)", new Object[]{speaker.getFirstName(), speaker.getLastName(), speaker.getEmail(), speaker.getBirthday()}); }
Spring 3
vendredi 19 février 2010
![Page 20: MarsJUG - Spring 3.0](https://reader033.vdocuments.mx/reader033/viewer/2022050721/55660b63d8b42aa6628b50ee/html5/thumbnails/20.jpg)
Supports
JDK 1.5+Rupture : JDK 1.4 n’est plus supporté
DépréciationHiérarchie de contrôleur Web
Hiérarchie de classe pour Junit 3.8
Le support de Struts 1.0
SuppressionLe support de Commons Attributes
Le support de Toplink 20vendredi 19 février 2010
![Page 21: MarsJUG - Spring 3.0](https://reader033.vdocuments.mx/reader033/viewer/2022050721/55660b63d8b42aa6628b50ee/html5/thumbnails/21.jpg)
DEMO DROP IN
vendredi 19 février 2010
![Page 22: MarsJUG - Spring 3.0](https://reader033.vdocuments.mx/reader033/viewer/2022050721/55660b63d8b42aa6628b50ee/html5/thumbnails/22.jpg)
Spring OXM
Inclusion du module de mapping Object / XML
Provient de Spring WS
Permet une abstraction des API communes
JAXB, JiBX, Xstream, Castor
Unification des exceptions
UtilisationGestion des payload REST en XML 22
vendredi 19 février 2010
![Page 23: MarsJUG - Spring 3.0](https://reader033.vdocuments.mx/reader033/viewer/2022050721/55660b63d8b42aa6628b50ee/html5/thumbnails/23.jpg)
JavaConfig
Configuration par annotations@Configuration, @Bean, @Lazy, @Primary, @Import, @Value
Version XML :<beans> <bean name=“monBean" class=“be.hikage.MonBeanImpl"/> </beans>
Version Annotation:@Configuration public class AppConfig { 23
vendredi 19 février 2010
![Page 24: MarsJUG - Spring 3.0](https://reader033.vdocuments.mx/reader033/viewer/2022050721/55660b63d8b42aa6628b50ee/html5/thumbnails/24.jpg)
Version Annotation
24
@Configuration public class AppConfig { @Bean public MonBean monBean() { return new MonBeanImpl(); } }
vendredi 19 février 2010
![Page 25: MarsJUG - Spring 3.0](https://reader033.vdocuments.mx/reader033/viewer/2022050721/55660b63d8b42aa6628b50ee/html5/thumbnails/25.jpg)
Expression Language
Syntaxe proche des Unified EL mais avec des fonctionnalités supplémentairesDéveloppé selon les besoins des projets du portfolioIndépendant
25vendredi 19 février 2010
![Page 26: MarsJUG - Spring 3.0](https://reader033.vdocuments.mx/reader033/viewer/2022050721/55660b63d8b42aa6628b50ee/html5/thumbnails/26.jpg)
EL : Synthaxe
26
Syntaxe Type
objet.propriete Appel des getters/setter
chaine.subString(2,3) Appel d’une méthode
array[2] Accès tableau par index
list[2] Accès liste par index
map[‘clé’] Map
vendredi 19 février 2010
![Page 27: MarsJUG - Spring 3.0](https://reader033.vdocuments.mx/reader033/viewer/2022050721/55660b63d8b42aa6628b50ee/html5/thumbnails/27.jpg)
EL : Synthaxe
27
Syntaxe Type
2 == 2 Opérateur
2 == 2 and 3 == 4 (faux)2 == 1 or 4 ==4 (vrai) Opérateur logique
5.00' matches '^-?\\d+(\\.\\d{2})?$' Regex
prenom ?:‘inconu’ Opérateur elvis
objet?.propriete?.proprieteFils Safe navigation
vendredi 19 février 2010
![Page 28: MarsJUG - Spring 3.0](https://reader033.vdocuments.mx/reader033/viewer/2022050721/55660b63d8b42aa6628b50ee/html5/thumbnails/28.jpg)
Expression Language
Attributs du contextesystemProperties, systemEnvironnent
Beans
Web :
contextParameters, contextAttributes
request, session
28vendredi 19 février 2010
![Page 29: MarsJUG - Spring 3.0](https://reader033.vdocuments.mx/reader033/viewer/2022050721/55660b63d8b42aa6628b50ee/html5/thumbnails/29.jpg)
EL : A venir
Utilisation dans les projets du portfolioExemple : Spring Security
29
<http use-expressions="true"> <intercept-url pattern="/secure/**" access="hasRole('ROLE_SUPERVISOR') and hasIpAddress('192.168.1.0/24')" /> ...</http>
vendredi 19 février 2010
![Page 30: MarsJUG - Spring 3.0](https://reader033.vdocuments.mx/reader033/viewer/2022050721/55660b63d8b42aa6628b50ee/html5/thumbnails/30.jpg)
Spring MVC
Namespace de configurationSupport de REST
Nouvelles vues : Xml, Json, RSS
Mécanisme de sélection de la vue selon la requête
API client
30vendredi 19 février 2010
![Page 31: MarsJUG - Spring 3.0](https://reader033.vdocuments.mx/reader033/viewer/2022050721/55660b63d8b42aa6628b50ee/html5/thumbnails/31.jpg)
REST
Intégré dans Spring @MVCFournir un support natif
Application visuelle Web
Service
Alternative : Utiliser JAX-RS et son modèle propre
31vendredi 19 février 2010
![Page 32: MarsJUG - Spring 3.0](https://reader033.vdocuments.mx/reader033/viewer/2022050721/55660b63d8b42aa6628b50ee/html5/thumbnails/32.jpg)
Exemple
32
vendredi 19 février 2010
![Page 33: MarsJUG - Spring 3.0](https://reader033.vdocuments.mx/reader033/viewer/2022050721/55660b63d8b42aa6628b50ee/html5/thumbnails/33.jpg)
REST – Limitation HTML
REST : Utilisation les méthodes HTTP :
GET,POST,PUT,DELETE
HTML ne gère que GET / POSTSolution : HiddenHttpMethodFilter
Taglib Spring MVC utilise cette solution
33vendredi 19 février 2010
![Page 34: MarsJUG - Spring 3.0](https://reader033.vdocuments.mx/reader033/viewer/2022050721/55660b63d8b42aa6628b50ee/html5/thumbnails/34.jpg)
REST – Content Negociation
URL = ResourcePlusieurs représentations possibles
Solution : ContentNegotiatingViewResolver
Délègue aux autres ViewResolver
Sélectionne celui qui correspond à la demande
34vendredi 19 février 2010
![Page 35: MarsJUG - Spring 3.0](https://reader033.vdocuments.mx/reader033/viewer/2022050721/55660b63d8b42aa6628b50ee/html5/thumbnails/35.jpg)
REST - Client
RestTemplateAPI de haut niveau pour REST
Accès au méthodes GET, PUT, POST, DELETE, OPTIONS
Gestion des conversions des objets
‣ HttpMessageConverter
Reste extensible par utilisation de CallBack
‣ Génération de la requête
‣ Traduction de la réponse
35vendredi 19 février 2010
![Page 36: MarsJUG - Spring 3.0](https://reader033.vdocuments.mx/reader033/viewer/2022050721/55660b63d8b42aa6628b50ee/html5/thumbnails/36.jpg)
Support du scheduling
Avant :Configuration verbeuse en XML
Définition du Scheduler
Définition du Trigger
Définition du Job
Définition du Bean « métier »
Après :
36vendredi 19 février 2010
![Page 37: MarsJUG - Spring 3.0](https://reader033.vdocuments.mx/reader033/viewer/2022050721/55660b63d8b42aa6628b50ee/html5/thumbnails/37.jpg)
Support du scheduling
Alternative : AnnotationCron
Delai fixe
Période fixe
37vendredi 19 février 2010
![Page 38: MarsJUG - Spring 3.0](https://reader033.vdocuments.mx/reader033/viewer/2022050721/55660b63d8b42aa6628b50ee/html5/thumbnails/38.jpg)
Support appel asynchrone
Permet de rendre asynchrone l’appel d’une méthode
Annotation @Asyn
Délègue l’appel à un TaskExecutor
38vendredi 19 février 2010
![Page 39: MarsJUG - Spring 3.0](https://reader033.vdocuments.mx/reader033/viewer/2022050721/55660b63d8b42aa6628b50ee/html5/thumbnails/39.jpg)
Support appel asynchrone
Cas 1 : Méthode sans résultat
Cas 2 : Méthode avec résultat
39vendredi 19 février 2010
![Page 40: MarsJUG - Spring 3.0](https://reader033.vdocuments.mx/reader033/viewer/2022050721/55660b63d8b42aa6628b50ee/html5/thumbnails/40.jpg)
Support des DB embarquées
Namespace jdbcPermet de configurer des bases embarquées
Derby
H2
HSQLDB
Permet de configurer des scripts d’initialisation
40vendredi 19 février 2010
![Page 41: MarsJUG - Spring 3.0](https://reader033.vdocuments.mx/reader033/viewer/2022050721/55660b63d8b42aa6628b50ee/html5/thumbnails/41.jpg)
Support Bean Validation
JSR 303 – Bean ValidationStandardisation de Hibernate Validator
Permet de configurer les contraintes de validation directement sur les objets métiers
41vendredi 19 février 2010
![Page 42: MarsJUG - Spring 3.0](https://reader033.vdocuments.mx/reader033/viewer/2022050721/55660b63d8b42aa6628b50ee/html5/thumbnails/42.jpg)
Support Bean Validation
Spring possède son propre système de validation
org.springframework.validation.Validator
Propose un adapteurLocalValidatorFactoryBean
Toutes couches Validation manuelle via injection du validateur 42
vendredi 19 février 2010
![Page 43: MarsJUG - Spring 3.0](https://reader033.vdocuments.mx/reader033/viewer/2022050721/55660b63d8b42aa6628b50ee/html5/thumbnails/43.jpg)
Support JSR 330 - @Inject
JSR initiée par SpringSource et Google
Propose un jeu d’annotations propre@Inject ↔ @AutoWired mais limité
@Qualifier ↔ @Qualifier mais limité
@Named ↔ @Qualifier sur le nom du Bean
@Singleton
@Scope 43vendredi 19 février 2010
![Page 44: MarsJUG - Spring 3.0](https://reader033.vdocuments.mx/reader033/viewer/2022050721/55660b63d8b42aa6628b50ee/html5/thumbnails/44.jpg)
DEMOREST
vendredi 19 février 2010
![Page 45: MarsJUG - Spring 3.0](https://reader033.vdocuments.mx/reader033/viewer/2022050721/55660b63d8b42aa6628b50ee/html5/thumbnails/45.jpg)
Spring 3.X Roadmap
Spring 3.1 : Début 2010Support complet de JEE 6
Support des conversations
45vendredi 19 février 2010
![Page 46: MarsJUG - Spring 3.0](https://reader033.vdocuments.mx/reader033/viewer/2022050721/55660b63d8b42aa6628b50ee/html5/thumbnails/46.jpg)
Conclusion
Spring 3.0Release majeure car rupture du JDK 1.4
Nouvelles fonctionnalités intéressantes
REST
SpEL
Bean Validation
Pas une révolution pour autant
46vendredi 19 février 2010
![Page 47: MarsJUG - Spring 3.0](https://reader033.vdocuments.mx/reader033/viewer/2022050721/55660b63d8b42aa6628b50ee/html5/thumbnails/47.jpg)
Spring 3 et JEE 6
vendredi 19 février 2010
![Page 48: MarsJUG - Spring 3.0](https://reader033.vdocuments.mx/reader033/viewer/2022050721/55660b63d8b42aa6628b50ee/html5/thumbnails/48.jpg)
Questions
vendredi 19 février 2010
![Page 49: MarsJUG - Spring 3.0](https://reader033.vdocuments.mx/reader033/viewer/2022050721/55660b63d8b42aa6628b50ee/html5/thumbnails/49.jpg)
Offert par Eyrolles
49vendredi 19 février 2010