O slideshow foi denunciado.
Utilizamos seu perfil e dados de atividades no LinkedIn para personalizar e exibir anúncios mais relevantes. Altere suas preferências de anúncios quando desejar.

Spring survey

670 visualizações

Publicada em

Publicada em: Tecnologia, Educação
  • Seja o primeiro a comentar

  • Seja a primeira pessoa a gostar disto

Spring survey

  1. 1. An Survey of Spring Chris Roeder March, 2011 This talk summarizes a lot of what is available in: Spring In Action , Craig Walls, Manning 2008
  2. 2. Spring is a collection of frameworks: <ul><li>IoC – an “Inversion of Control” </li><ul><li>AKA: Dependency Injection Framework </li></ul><li>Data Access,Transaction Management, Security
  3. 3. Remote Access Framework
  4. 4. Spring Dynamic Modules
  5. 5. Aspects – a way to deal with “cross cutting concerns”
  6. 6. MVC – an alternative to web application frameworks like Struts </li></ul>
  7. 7. Spring does not re-invent the wheel <ul><li>Uses existing logging frameworks
  8. 8. Uses existing anything: ORM, transactions, Aspects, Remoting, etc.
  9. 9. Spring is there to provide “portability” between frameworks that share a purpose and interface </li></ul>
  10. 10. Spring Frameworks are Abstractions <ul><li>Frameworks are collections of Java interfaces
  11. 11. Implemented by a variety of solutions: </li><ul><li>Hibernate, JPA, Toplink </li></ul><li>“Injected” into your code by the config file using the Java Bean Interface (more)
  12. 12. Leaving your code simple and full of POJOs (more later)
  13. 13. When needs require a different implementation, very easy to change the config file with no code changes </li></ul>
  14. 14. Detail: Java Bean <ul><li>“A JavaBean is a Java Object that is serializable, has a nullary constructor, and allows access to properties using getter and setter methods.” </li><ul><li>http://en.wikipedia.org/wiki/JavaBean </li></ul><li>Not an Entity Java Bean or EJB </li></ul>
  15. 15. Detail: POJO <ul><li>“The name is used to emphasize that a given object is an ordinary Java Object, not a special object, and in particular not an Enterprise JavaBean” </li><ul><li>http://en.wikipedia.org/wiki/Plain_Old_Java_Object </li></ul><li>Meaning it's not tied to a particular framework. </li></ul>
  16. 16. Inversion of Control or Dependency Injection? <ul><li>Inversion of Control is a general concept that relates to event-driven programming where the stream of events dictates execution.
  17. 17. Dependency Injection is a more specific concept that refers to setting values on objects (Java Beans) from an external source.
  18. 18. Spring calls the framework IoC.
  19. 19. I call the concept used here DI. </li></ul>
  20. 20. Detail: IoC <ul><li>Dependency Injection (DI) involves abstracting out the introduction of a project's components.
  21. 21. Even with good modularity, you still hard-code them together with code like this:
  22. 22. public static void main(String args[]) { DataProvider dp = new DataProvider(); CorpMetrics metrics = new CorpMetrics(); metrics.calculate(dp); </li></ul>
  23. 23. Detail: IoC 2 <ul><li>In other situations, JDBC in EJB for example, collaborators aren't hard-coded, but find each other at runtime:
  24. 24. A JDBC setup finds its database connection by consulting JNDI, making environmental assumptions: Context initContext = new InitialContext(); Context envContext = (Context)initContext.lookup(&quot;java:/comp/env&quot;); DataSource ds = (DataSource)envContext.lookup(&quot;jdbc/myoracle&quot;); Connection conn = ds.getConnection(); ( http://tomcat.apache.org/tomcat-5.5-doc/jndi-datasource-examples-howto.html )
  25. 25. Changes still involve changing the java code. </li></ul>
  26. 26. Detail: IoC 3 <ul><li>Separate classes allows flexibility
  27. 27. Hard-coded constructor calls limit it.
  28. 28. Unit Testing with different configurations is made easier.
  29. 29. IoC is used as a supporting technology throughout Spring
  30. 30. UIMA users, as described in a 2009 poster paper, would find this eerily familiar </li><ul><li>A bit of programmer humor would involve using uimaFIT and Spring to define a pipeline in a Spring config file instead of a CPE. </li></ul></ul>
  31. 31. Detail: IoC 4 <ul><li>Alternate implementations require interfaces:
  32. 32. Code to Interfaces
  33. 33. Create “new” implementations of Classes that implement them.
  34. 34. Easy to swap with a different implementation when both implement the same Java interface.
  35. 35. Also works to enable a kind of multiple inheritance in Java. </li></ul>
  36. 36. Survey: Data Access <ul><li>POJO model entities can be stored in any ORM tool, just plain JDBC or others
  37. 37. Operations on entities built in Data Access Objects (DAO) </li><ul><li>GetById(), GetListWhere(), Update(), etc. </li></ul><li>Spring provides “templates” to make building DAOs easy
  38. 38. BTW, these are used in FLEX integration </li></ul>
  39. 39. Survey: Transaction Management <ul><li>Abstracts on top of JDBC, Hibernate, JPA, JMS, EJB transaction.jta.* classes
  40. 40. Databases handle their own transactions: </li><ul><li>START TRANSACTION, SAVE TRANSACTION </li></ul><li>EJB containers allow transactions between multiple systems
  41. 41. Coding to Spring allows flexibility and growth </li></ul>
  42. 42. Survey: Remote Access <ul><li>Compares to RMI, SOAP WS, Hessian, Burlap
  43. 43. Abstracts the concept of remoting and provides different implementations.
  44. 44. Client and service objects are POJOs.
  45. 45. Can make use of JSR-181 Web Services Metadata annotations </li></ul>
  46. 46. Survey: Dynamic Modules <ul><li>Spring-DM is an implementation and integration of OSGI modules into Spring.
  47. 47. provide another layer of encapsulation over the concept of Class. Now you can have private and public classes as members of a module (jar).
  48. 48. allow for a lifecycle, so module can have a “running” state.
  49. 49. provide better naming, so versions can be included.
  50. 50. provide restricted “class space”, allowing for more than one version of a class at the same time.
  51. 51. More: Yuriy is working on this </li></ul>
  52. 52. Survey: Aspects <ul><li>Cross-Cutting Concern: “functions that span multiple points of an application”
  53. 53. Logging, Transactions, Security
  54. 54. Makes use of a proxy facility in Java reflection. </li><ul><li>Instead of creating and using a new object, you create the object and a proxy around it. Then use the proxy in it's place.
  55. 55. The proxy intercepts function calls and allows implementations of a Handler interface to intercept them. </li></ul><li>Other Implementations exist, but are intrusive. </li></ul>
  56. 56. Survey: MVC <ul><li>Spring has a Model, View, Control (MVC) framework for web applications. It separates code into three types: </li><ul><li>Model – the data and functions to manipulate it
  57. 57. View – the JSP pages to render a web page
  58. 58. Controller – the plumbing or routing </li></ul><li>A kind of “Model 2” architecture where a controller servlet controls creates beans and introduces them to JSPs </li><ul><li>Model 1 architecture is js JSP and Bean, leaving much to the JSP and scriptlets. </li></ul></ul>
  59. 59. Links <ul><li>http://www.theserverside.com/news/1364527/Introduction-to-the-Spring-Framework </li></ul>