SlideServe
Menu
Préférences
© SlideServe · v2026

Spring Framework Fundamentals

tamma avatar
18 diapositives · 452 Views · Aug 21, 2014

Spring Framework Fundamentals. March, 2006 Larry Hamel Codeguild, Inc. http://codeguild.com/. Framework Defined. A framework provides tools, designs, templates, and practices to somehow make development easier

Spring Framework Fundamentals - slide 1
01 / 18Spring Framework Fundamentals
1 / 17

Télécharger la présentation

Spring Framework Fundamentals
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. Spring Framework Fundamentals March, 2006 Larry Hamel Codeguild, Inc. http://codeguild.com/

  2. Framework Defined • A framework provides tools, designs, templates, and practices to somehow make development easier • Java frameworks tend to divide into front-end (display), middle (control logic), and/or back-end (persistance) functions

  3. Struts (2001) Avalon (1999) Cocoon (1999) Expresso (2000) Webwork JavaServer Faces (2004)/Shale Seam (2005) Spring (2002) Tapestry Struts Action Framework (from Webwork) 2005 Hibernate Java Frameworks(parial list)

  4. Outline • Two criteria for judging a framework • Loose coupling/Inversion of Control (IoC)/Dependency injection • Aspect-oriented programming (AOP) • Choosing a framework

  5. Why is IoC important? • Integrate with other frameworks, other services • plug in a persistence layer, a display layer, etc. • Extensive unit-test coverage of framework code • the less dependence between classes, the easier to test

  6. Interface vs. Concrete • Interface is a specification of signatures—no implementation • Concrete class has implementation of every method; can be instantiated • (Abstract class is in between—some, but not all, methods implemented)

  7. Tight Coupling class Foo { void bar() { FastStringBuffer aBuffer = FastStringBuffer. getInstance(); // ... } }

  8. Loose Coupling StringBufferFactoryInterface aBuffFac = getStringBuffer(); ------------------------------------ public StringBufferFactoryInterfacegetStringBuffer() { /* ??? how implement with no dependence ??? */ }

  9. Loose Coupling (IoC) StringBufferFactoryInterface aBuffFac = getStringBuffer(); ----------------------------------------- public StringBufferFactoryInterfacegetStringBuffer() { return stringBufferFac; } public void setStringBuffer( StringBufferFactoryInterface aBuff) { stringBufferFac = aBuff; } private StringBufferFactoryInterfacestringBufferFac;

  10. Spring configuration, injecting dependencies <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN“ ...> <beans> <bean id=“fastStringBuffer” class=“FastStringBuffer” /> <bean id=“myClient” class=“Foo”> <property name=“stringBuffer"> <ref local="fastStringBuffer"/> </property> </bean> </beans>

  11. Spring is an IoC Bean Factory InputStream is = new FileInputStream("src/examples/spring/beans.xml"); BeanFactory factory = new XmlBeanFactory(is); DataProcessor dataProcessor = (DataProcessor) factory.getBean("fileDataProcessor"); Result result = dataProcessor.processData();

  12. Aspect-Oriented Programming (AOP) Rationale • Object oriented programming (OOP) isn’t good at everything. • Consider: • Security: want to test privileges every time method is invoked. • DB transactions: want to have every access to DB run through transaction

  13. Transaction OO example DBConnection conn = DBConnectionPool.getInstance() .getConnection("course clone"); try { conn.setAutoCommit(false); Course clonecourse = new Course(conn); ... } catch (Exception e) { conn.rollback(); getLogger().error(e); } finally { conn.release(); }

  14. AOP • Transactions, Logging and Security are often referred to as “crosscutting” concerns, applying to all objects • For every method, AOP inserts ‘advice’ before and/or after method call • Spring uses dynamic AOP, creating “proxies” for all advised objects

  15. AOP Example in Spring • Using JDK1.5 annotations! @Transactional public void saveCourse( Course src) { getCourseDBO().save(src); }

  16. Choosing the Right Tool • If you already know tool ++ • Currently popular tool ++ • Estimate lifespan of project • Estimate audience (users) • Estimate need to interface with external resources (email, LDAP) • Impartial, comprehensive reviews are hard to find • Any framework will go obsolete!

  17. Opinion • Is two-tier PHP good enough? • Bigger projects: take care not to overestimate—”You’re not going to need it” • Watch: • Ruby on Rails (David Hansson) • Seam (Gavin King) • Spring (Rod Johnson)

  18. http://codeguild.com/presentations/