CUST-9 Spring Config for Alfresco Developers


Published on

Alfresco is built using the best of breed open-source components, designed with extensibility in mind. Heavily utilizing the Spring Framework, Alfresco provides hooks to update basic configuration, customize behavior and presentation, add new functionality, and even replace entire subsystems. This talk will cover different Spring configuration options available and demonstrate specific use cases for Alfresco.

Published in: Technology, Education
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

CUST-9 Spring Config for Alfresco Developers

  1. 1. Spring Configuration for Alfresco Developers! Hitesh Lad Principal Engineer Sony Pictures!
  2. 2. Agenda! Spring Overview Dependency Injection Bean Definitions Alfresco Spring Bootstrap Some Examples
  3. 3. What is Spring?! •  The most popular application development framework for enterprise Java •  Based on code published in “Expert One-on-One J2EE Design and Development” by Rod Johnson (Wrox, 2002). •  Made up of many modules •  Fosters integration with good existing solutions
  4. 4. What is a Spring Bean?!•  Plain Old Java Objects! •  No special interfaces or base classes needed! •  Usually have getter and setter methods for accessing properties! •  Can be interrogated or manipulated via the Java Reflection API!•  Focused on implementing your business logic! •  Across all tiers of your application! •  Usually highly cohesive!•  Not an old pre-3.0 EJB!!•  Usually agnostic to the Spring container!
  5. 5. Agenda! Spring Overview Dependency Injection Bean Definitions Alfresco Spring Bootstrap Some Examples
  6. 6. What is Dependency Injection?!•  Springʼs Dependency Injection instantiates and combines beans to form your application!•  Decouples the configuration and specification of dependencies from your actual program logic!•  Removes the need for programmatic singletons!•  Beans should implements and depend on interfaces!
  7. 7. Dependency Injection Example!
  8. 8. Dependency Injection Example, cont.!
  9. 9. Dependency Injection Example - XML!
  10. 10. BeanFactory and ApplicationContext!•  org.springframework.beans.factory.BeanFactory•  Base interface for actual Spring DI container!•  Instantiates or sourcing application objects!•  Configures such objects!•  Assembles the dependencies between these objects!•  org.springframework.context.ApplicationContext•  ApplicationContext is a complete superset of a BeanFactory!•  adds enhanced capabilities to it, more J2EE and enterprise-centric!
  11. 11. BeanFactories and ApplicationContexts!
  12. 12. Bean Definition!Bean are represented as BeanDefinition objects!•  Bean Identifier(s)!•  Class name!•  Bean Properties / Constructor-Args!•  Behavioral Elements!•  Definition Reuse!
  13. 13. Bean Definition - Identifiers!•  All beans must have at least 1 identifier!•  Beans identifiers must be unique withind BeanFactory!•  Prefer using id attribute vs name attribute!•  Multiple identifiers are considered aliases!
  14. 14. Bean Definition - Class Names!•  Class attribute is usually the class we want to construct!•  Class is almost always needed! •  Except for non-static factory beans and abstract beans!•  Use fully qualified class names!•  FactoryBean interface build object of different types!
  15. 15. Bean Definition - Properties!•  Writeable Bean Properties correspond to “setters”!•  Property name follows JavaBean convention!•  Values set can be primitives or objects! •  Static values, e.g. Strings, ints, …! •  Property lookups, from a Properties file or Environment variable! •  Other bean definitions references!
  16. 16. Bean Definition – Contructor Args!•  Number/Type of arguments must match an existing constructor!•  Useful for explicitly requiring dependencies!•  Constructor argument names are usually “erased” during compilation !! •  Sometimes “index” or “type” needed to disambiguate!
  17. 17. Bean Definition – Contructor Args!
  18. 18. Bean Definition – Bean Scope!•  Bean default scope is ʻsingletonʼ per BeanFactory!•  Other scopes – Prototype, Session & Request!
  19. 19. Bean Definition – Reuse!
  20. 20. Bean Definition - Reuse!
  21. 21. Bean Definition – Ordering!
  22. 22. Bean Definition - Recap! •  Bean Identifier(s)! •  Class name! •  Usually the class weʼre constructing! •  Bean Properties / Constructor-Args! •  Static values! •  Property lookups! •  Other bean definitions references! •  Behavioral Elements! •  Scope! •  Initialization / Destruction! •  Definition Reuse!
  23. 23. Agenda! Spring Overview Dependency Injection Bean Definitions Alfresco Spring Bootstrap Some Examples
  24. 24. Spring in Alfresco!
  25. 25. alfresco.war - web.xml!
  26. 26. alfresco.war - web-application-context.xml!
  27. 27. alfresco.war - application-context.xml!
  28. 28. Agenda! Spring Overview Dependency Injection Bean Definitions Alfresco Spring Bootstrap Some Examples
  29. 29. Adding a custom model!
  30. 30. custom-model-context.xml!
  31. 31. alfresco.war – core-services-context.xml!
  32. 32. Adding a custom Web Script !
  33. 33.!
  34. 34. web-scripts-application-context.xml!
  35. 35. Agenda! Spring Overview Dependency Injection Bean Definitions Alfresco Spring Bootstrap Some Examples
  36. 36. References!For More Information, check out the following:!• framework-reference/html/beans.html!• backed_Web_Scripts_Samples!•!• (My Blog)!
  37. 37. Questions?!