cust-9 spring config for alfresco developers
Post on 18-Dec-2014
1.430 Views
Preview:
DESCRIPTION
TRANSCRIPT
Spring Configuration for Alfresco Developers!
Hitesh Lad Principal Engineer Sony Pictures!
Agenda!
Spring Overview
Dependency Injection
Bean Definitions
Alfresco Spring Bootstrap
Some Examples
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
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!
Agenda!
Spring Overview
Dependency Injection
Bean Definitions
Alfresco Spring Bootstrap
Some Examples
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!
Dependency Injection Example!
Dependency Injection Example, cont.!
Dependency Injection Example - XML!
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!
BeanFactories and ApplicationContexts!
Bean Definition!
Bean are represented as BeanDefinition objects!
• Bean Identifier(s)!
• Class name!
• Bean Properties / Constructor-Args!
• Behavioral Elements!
• Definition Reuse!
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!
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!
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!
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!
Bean Definition – Contructor Args!
Bean Definition – Bean Scope!
• Bean default scope is ʻsingletonʼ per BeanFactory!• Other scopes – Prototype, Session & Request!
Bean Definition – Reuse!
Bean Definition - Reuse!
Bean Definition – Ordering!
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!
Agenda!
Spring Overview
Dependency Injection
Bean Definitions
Alfresco Spring Bootstrap
Some Examples
Spring in Alfresco!
alfresco.war - web.xml!
alfresco.war - web-application-context.xml!
alfresco.war - application-context.xml!
Agenda!
Spring Overview
Dependency Injection
Bean Definitions
Alfresco Spring Bootstrap
Some Examples
Adding a custom model!
custom-model-context.xml!
alfresco.war – core-services-context.xml!
Adding a custom Web Script !
HelloWorldWebScript.java!
web-scripts-application-context.xml!
Agenda!
Spring Overview
Dependency Injection
Bean Definitions
Alfresco Spring Bootstrap
Some Examples
References!
For More Information, check out the following:!
• http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/beans.html!
• http://wiki.alfresco.com/wiki/Java-backed_Web_Scripts_Samples!
• http://wiki.alfresco.com/wiki/Data_Dictionary_Guide!
• http://java1337.com/ (My Blog)!
Questions?!
top related