🗊Презентация Introduction to spring framework and dependency injection

Нажмите для полного просмотра!
Introduction to spring framework and dependency injection, слайд №1Introduction to spring framework and dependency injection, слайд №2Introduction to spring framework and dependency injection, слайд №3Introduction to spring framework and dependency injection, слайд №4Introduction to spring framework and dependency injection, слайд №5Introduction to spring framework and dependency injection, слайд №6Introduction to spring framework and dependency injection, слайд №7Introduction to spring framework and dependency injection, слайд №8Introduction to spring framework and dependency injection, слайд №9Introduction to spring framework and dependency injection, слайд №10Introduction to spring framework and dependency injection, слайд №11Introduction to spring framework and dependency injection, слайд №12Introduction to spring framework and dependency injection, слайд №13Introduction to spring framework and dependency injection, слайд №14Introduction to spring framework and dependency injection, слайд №15Introduction to spring framework and dependency injection, слайд №16Introduction to spring framework and dependency injection, слайд №17Introduction to spring framework and dependency injection, слайд №18Introduction to spring framework and dependency injection, слайд №19Introduction to spring framework and dependency injection, слайд №20Introduction to spring framework and dependency injection, слайд №21Introduction to spring framework and dependency injection, слайд №22Introduction to spring framework and dependency injection, слайд №23Introduction to spring framework and dependency injection, слайд №24Introduction to spring framework and dependency injection, слайд №25Introduction to spring framework and dependency injection, слайд №26Introduction to spring framework and dependency injection, слайд №27Introduction to spring framework and dependency injection, слайд №28Introduction to spring framework and dependency injection, слайд №29Introduction to spring framework and dependency injection, слайд №30Introduction to spring framework and dependency injection, слайд №31

Вы можете ознакомиться и скачать презентацию на тему Introduction to spring framework and dependency injection. Доклад-сообщение содержит 31 слайдов. Презентации для любого класса можно скачать бесплатно. Если материал и наш сайт презентаций Mypresentation Вам понравились – поделитесь им с друзьями с помощью социальных кнопок и добавьте в закладки в своем браузере.

Слайды и текст этой презентации


Слайд 1





Introduction to 
Spring Framework
 and Dependency Injection
Aaron Zeckoski
azeckoski@gmail.com
Описание слайда:
Introduction to Spring Framework and Dependency Injection Aaron Zeckoski azeckoski@gmail.com

Слайд 2





Spring Framework
A popular and stable Java application framework for enterprise development
Ubiquitous for Java development
Well established in enterprise Java apps
Time tested and proven reliable
A primary purpose is to reduce dependencies and even introduce negative dependencies
Different from almost every other framework out there
Part of the reason it has been adopted so quickly
Описание слайда:
Spring Framework A popular and stable Java application framework for enterprise development Ubiquitous for Java development Well established in enterprise Java apps Time tested and proven reliable A primary purpose is to reduce dependencies and even introduce negative dependencies Different from almost every other framework out there Part of the reason it has been adopted so quickly

Слайд 3





Spring code structure
Spring code base is proven to be well structured (possibly the best)
http://chris.headwaysoftware.com/2006/07/springs_structu.html
Analysis using Structure 101
139 packages
No dependency cycles
Описание слайда:
Spring code structure Spring code base is proven to be well structured (possibly the best) http://chris.headwaysoftware.com/2006/07/springs_structu.html Analysis using Structure 101 139 packages No dependency cycles

Слайд 4





More Spring
Considered an alternative / replacement for the Enterprise JavaBean (EJB) model
Flexible
Programmers decide how to program
Not exclusive to Java (e.g. .NET)
Solutions to typical coding busywork
JDBC
LDAP
Web Services
Описание слайда:
More Spring Considered an alternative / replacement for the Enterprise JavaBean (EJB) model Flexible Programmers decide how to program Not exclusive to Java (e.g. .NET) Solutions to typical coding busywork JDBC LDAP Web Services

Слайд 5





What does Spring offer?
Dependency Injection
Also known as IoC (Inversion of Control)
Aspect Oriented Programming
Runtime injection-based
Portable Service Abstractions
The rest of spring
ORM, DAO, Web MVC, Web, etc.
Allows access to these without knowing how they actually work
Описание слайда:
What does Spring offer? Dependency Injection Also known as IoC (Inversion of Control) Aspect Oriented Programming Runtime injection-based Portable Service Abstractions The rest of spring ORM, DAO, Web MVC, Web, etc. Allows access to these without knowing how they actually work

Слайд 6





Dependency Injection defined
Method to create needed dependencies or look them up somehow without doing it in the dependent code
Often called Inversion of Control (IoC)
IoC injects needed dependencies into the object instead
Setters or Contructor
Primary goal is reduction of dependencies in code
an excellent goal in any case
This is the central part of Spring
Описание слайда:
Dependency Injection defined Method to create needed dependencies or look them up somehow without doing it in the dependent code Often called Inversion of Control (IoC) IoC injects needed dependencies into the object instead Setters or Contructor Primary goal is reduction of dependencies in code an excellent goal in any case This is the central part of Spring

Слайд 7





Aspect Oriented Programming defined
Attempts to separate concerns, increase modularity, and decrease redundancy
Separation of Concerns (SoC)
Break up features to minimize overlap
Don’t Repeat Yourself (DRY)
Minimize code duplication 
Cross-Cutting Concerns
Program aspects that affect many others (e.g. logging)
AspectJ is the top AOP package
Java like syntax, IDE integration
Описание слайда:
Aspect Oriented Programming defined Attempts to separate concerns, increase modularity, and decrease redundancy Separation of Concerns (SoC) Break up features to minimize overlap Don’t Repeat Yourself (DRY) Minimize code duplication Cross-Cutting Concerns Program aspects that affect many others (e.g. logging) AspectJ is the top AOP package Java like syntax, IDE integration

Слайд 8





Portable Service Abstractions defined
Services that easily move between systems without heavy reworking
Ideally easy to run on any system
Abstraction without exposing service dependencies
LDAP access without knowing what LDAP is
Database access without typical JDBC hoops
Basically everything in Spring that is not IoC or AOP
Описание слайда:
Portable Service Abstractions defined Services that easily move between systems without heavy reworking Ideally easy to run on any system Abstraction without exposing service dependencies LDAP access without knowing what LDAP is Database access without typical JDBC hoops Basically everything in Spring that is not IoC or AOP

Слайд 9





What is a bean?
Typical java bean with a unique id
In spring there are basically two types
Singleton
One instance of the bean created and referenced each time it is requested
Prototype (non-singleton)
New bean created each time
Same as new ClassName()
Beans are normally created by Spring as late as possible
Описание слайда:
What is a bean? Typical java bean with a unique id In spring there are basically two types Singleton One instance of the bean created and referenced each time it is requested Prototype (non-singleton) New bean created each time Same as new ClassName() Beans are normally created by Spring as late as possible

Слайд 10





What is a bean definition?
Defines a bean for Spring to manage
Key attributes
class (required): fully qualified java class name
id: the unique identifier for this bean
configuration: (singleton, init-method, etc.)
constructor-arg: arguments to pass to the constructor at creation time
property: arguments to pass to the bean setters at creation time
Collaborators: other beans needed in this bean (a.k.a dependencies), specified in property or constructor-arg
Typically defined in an XML file
Описание слайда:
What is a bean definition? Defines a bean for Spring to manage Key attributes class (required): fully qualified java class name id: the unique identifier for this bean configuration: (singleton, init-method, etc.) constructor-arg: arguments to pass to the constructor at creation time property: arguments to pass to the bean setters at creation time Collaborators: other beans needed in this bean (a.k.a dependencies), specified in property or constructor-arg Typically defined in an XML file

Слайд 11





Sample bean definition
Описание слайда:
Sample bean definition

Слайд 12





What is a bean factory?
Often seen as an ApplicationContext
BeanFactory is not used directly often
ApplicationContext is a complete superset of bean factory methods
Same interface implemented
Offers a richer set of features
Spring uses a BeanFactory to create, manage and locate “beans” which are basically instances of a class
Typical usage is an XML bean factory which allows configuration via XML files
Описание слайда:
What is a bean factory? Often seen as an ApplicationContext BeanFactory is not used directly often ApplicationContext is a complete superset of bean factory methods Same interface implemented Offers a richer set of features Spring uses a BeanFactory to create, manage and locate “beans” which are basically instances of a class Typical usage is an XML bean factory which allows configuration via XML files

Слайд 13





How are beans created?
Beans are created in order based on the dependency graph
Often they are created when the factory loads the definitions
Can override this behavior in bean
<bean class=“className” lazy-init=“true” />
You can also override this in the factory or context but this is not recommended
Spring will instantiate beans in the order required by their dependencies
app scope singleton - eagerly instantiated at container startup
lazy dependency - created when dependent bean created
VERY lazy dependency - created when accessed in code
Описание слайда:
How are beans created? Beans are created in order based on the dependency graph Often they are created when the factory loads the definitions Can override this behavior in bean <bean class=“className” lazy-init=“true” /> You can also override this in the factory or context but this is not recommended Spring will instantiate beans in the order required by their dependencies app scope singleton - eagerly instantiated at container startup lazy dependency - created when dependent bean created VERY lazy dependency - created when accessed in code

Слайд 14





How are beans injected?
A dependency graph is constructed based on the various bean definitions
Beans are created using constructors (mostly no-arg) or factory methods
Dependencies that were not injected via constructor are then injected using setters
Any dependency that has not been created is created as needed
Описание слайда:
How are beans injected? A dependency graph is constructed based on the various bean definitions Beans are created using constructors (mostly no-arg) or factory methods Dependencies that were not injected via constructor are then injected using setters Any dependency that has not been created is created as needed

Слайд 15





Multiple bean config files
There are 3 ways to load multiple bean config files (allows for logical division of beans)
Load multiple config files from web.xml
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:/WEB-INF/spring-config.xml, classpath:/WEB-INF/applicationContext.xml</param-value>
</context-param>
Use the import tag
<import resource="services.xml"/>
Load multiple config files using Resources in the application context constructor
Recommended by the spring team
Not always possible though
ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext( new String[] {"applicationContext.xml", "applicationContext-part2.xml"});
Описание слайда:
Multiple bean config files There are 3 ways to load multiple bean config files (allows for logical division of beans) Load multiple config files from web.xml <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:/WEB-INF/spring-config.xml, classpath:/WEB-INF/applicationContext.xml</param-value> </context-param> Use the import tag <import resource="services.xml"/> Load multiple config files using Resources in the application context constructor Recommended by the spring team Not always possible though ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext( new String[] {"applicationContext.xml", "applicationContext-part2.xml"});

Слайд 16





Bean properties?
The primary method of dependency injection
Can be another bean, value, collection, etc.
Описание слайда:
Bean properties? The primary method of dependency injection Can be another bean, value, collection, etc.

Слайд 17





Anonymous vs ID
Beans that do not need to be referenced elsewhere can be defined anonymously
This bean is identified (has an id) and can be accessed to inject it into another bean
Описание слайда:
Anonymous vs ID Beans that do not need to be referenced elsewhere can be defined anonymously This bean is identified (has an id) and can be accessed to inject it into another bean

Слайд 18





What is an inner bean?
It is a way to define a bean needed by another bean in a shorthand way
Always anonymous (id is ignored)
Always prototype (non-singleton)
Описание слайда:
What is an inner bean? It is a way to define a bean needed by another bean in a shorthand way Always anonymous (id is ignored) Always prototype (non-singleton)

Слайд 19





Bean init-method
The init method runs AFTER all bean dependencies are loaded
Constructor loads when the bean is first instantiated
Allows the programmer to execute code once all dependencies are present
Описание слайда:
Bean init-method The init method runs AFTER all bean dependencies are loaded Constructor loads when the bean is first instantiated Allows the programmer to execute code once all dependencies are present

Слайд 20





Bean values
Spring can inject more than just other beans
Values on beans can be of a few types
Direct value (string, int, etc.)
Collection (list, set, map, props)
Bean
Compound property
Описание слайда:
Bean values Spring can inject more than just other beans Values on beans can be of a few types Direct value (string, int, etc.) Collection (list, set, map, props) Bean Compound property

Слайд 21





Abstract (parent) beans
Allows definition of part of a bean which can be reused many times in other bean definitions
Описание слайда:
Abstract (parent) beans Allows definition of part of a bean which can be reused many times in other bean definitions

Слайд 22





AOP in Spring
Provides way to create declarative services and custom aspects
Transaction management is the most common aspect (or concern)
Spring handles AOP via advisors or interceptors
Interception point is a joinpoint
A set of joinpoints are called a pointcut
pointcuts are key to Spring AOP, they allow intercepts without explicit knowledge of the OO hierarchy
Action taken by an interceptor is called advice
Описание слайда:
AOP in Spring Provides way to create declarative services and custom aspects Transaction management is the most common aspect (or concern) Spring handles AOP via advisors or interceptors Interception point is a joinpoint A set of joinpoints are called a pointcut pointcuts are key to Spring AOP, they allow intercepts without explicit knowledge of the OO hierarchy Action taken by an interceptor is called advice

Слайд 23





AOP advice types
Around
Most common and powerful
Execute code before and after joinpoint
Before
Executes before joinpoint, cannot stop execution
Throws
Executes code if exception is thrown
After return
Executes code after normal joinpoint execution
Описание слайда:
AOP advice types Around Most common and powerful Execute code before and after joinpoint Before Executes before joinpoint, cannot stop execution Throws Executes code if exception is thrown After return Executes code after normal joinpoint execution

Слайд 24





Spring AOP key points
Pure java implementation
Allows method interception
No field or property intercepts yet
AOP advice is specified using typical bean definitions
Closely integrates with Spring IoC
Proxy based AOP
J2SE dynamic proxies or CGLIB proxies
Not a replacement for AspectJ
Описание слайда:
Spring AOP key points Pure java implementation Allows method interception No field or property intercepts yet AOP advice is specified using typical bean definitions Closely integrates with Spring IoC Proxy based AOP J2SE dynamic proxies or CGLIB proxies Not a replacement for AspectJ

Слайд 25





Example transaction proxy
This wraps a transaction interceptor around a DAO
Описание слайда:
Example transaction proxy This wraps a transaction interceptor around a DAO

Слайд 26





Working example
Let’s look at some example code pre and post spring
Simple application that allows a user to add, remove, and list a set of strings
Pre spring code
Programmers Cafe - Example App
Post spring code
Programmers Cafe - Example App Spring
Описание слайда:
Working example Let’s look at some example code pre and post spring Simple application that allows a user to add, remove, and list a set of strings Pre spring code Programmers Cafe - Example App Post spring code Programmers Cafe - Example App Spring

Слайд 27





Example App
The example app is a simple command line Java app which is meant to demonstrate a reasonable dependency structure
This app allows a user to save, delete, and list a set of strings associated with their username
Описание слайда:
Example App The example app is a simple command line Java app which is meant to demonstrate a reasonable dependency structure This app allows a user to save, delete, and list a set of strings associated with their username

Слайд 28





Example App Structure
Alpha is the main class
Bravo handles user interaction
Charlie handles application logic
Delta handles data access
Dependency graph is non-cyclical
No A => B => C => A
Описание слайда:
Example App Structure Alpha is the main class Bravo handles user interaction Charlie handles application logic Delta handles data access Dependency graph is non-cyclical No A => B => C => A

Слайд 29





Non-spring version
Involves using new to create needed dependencies
Each class must know about the dependencies that it needs
Singletons have to be created and handed to the classes that need them at the same time or you need a static way to access them (or a framework)
Tightly coupled code structure
Описание слайда:
Non-spring version Involves using new to create needed dependencies Each class must know about the dependencies that it needs Singletons have to be created and handed to the classes that need them at the same time or you need a static way to access them (or a framework) Tightly coupled code structure

Слайд 30





Spring version
No more new use
Classes only have to know about the interface
or class if no interface available
Singletons easy to handle
Loose coupling allows flexible changes
Описание слайда:
Spring version No more new use Classes only have to know about the interface or class if no interface available Singletons easy to handle Loose coupling allows flexible changes

Слайд 31





Questions?
Spring framework
http://www.springframework.org/
Описание слайда:
Questions? Spring framework http://www.springframework.org/



Похожие презентации
Mypresentation.ru
Загрузить презентацию