1 / 18

Spring Framework Fundamentals

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

tamma
Télécharger la présentation

Spring Framework Fundamentals

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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/

More Related