This document discusses the Spring Framework, including its origins, core features like inversion of control and dependency injection, and how it can be used for tasks like building web applications and performing data access. It provides an overview of Spring's capabilities for managing object lifecycles, performing declarative transactions, and implementing aspects like caching and asynchronous programming. The document also touches on some common criticisms of Spring and encourages developers to avoid over-engineering solutions.
2. About us
Software Engineers
Working with Spring since 2006
Pragmatic programmers
SpringByExample.com.ua
founders
SpringByExample.com.ua
2
@ua_spring #uadevclub
3. Contents
Spring origins
IoC using Spring
Persistence with Spring
Declarative caching using @Cachable
Web applications with Spring MVC
Spring ecosystem
Framework criticism
SpringByExample.com.ua
3
@ua_spring #uadevclub
5. SpringFramework
history
In October 2002 Rod Johnson wrote
his famous book
The first milestone release 1.0 -
June 2004
Company renamed from Interface21
to SpringSource in 2007
SpringSource acquired by VMWare
in 2009
Rod Johnson left VMWare – July
2012
SpringByExample.com.ua
5
@ua_spring #uadevclub
6. Inversion of Control
Inversion of regular approach where object was
responsible for satisfying it’s own dependencies
Implementation of Dependency Injection
Container instantiates and wires dependencies
SpringByExample.com.ua
6
@ua_spring #uadevclub
7. Injection types
Setter injection– when you are using setter to fulfill
bean dependency
Constructor injection – when constructor is called to
set-up a bean with dependencies
Method injection
SpringByExample.com.ua
7
@ua_spring #uadevclub
8. Context
An object which contains beans declarations with
their dependencies
BeanFactory interface implementation
SpringByExample.com.ua
8
@ua_spring #uadevclub
9. XML namespaces
SpringByExample.com.ua
9
@ua_spring #uadevclub
12. Bean lifecycle
Depends on scope and lazy initialization
Main bean scopes:
Singleton and Prototype
(Also there are multiple web scopes)
SpringByExample.com.ua
12
@ua_spring #uadevclub
14. Bean Post-processing
• Bean instantiated for singletons with
Bean
instantiation
eager initialization
Dependency
• Dependencies are injected into beans
injection
• Bean post-processing actions
Bean post-
processing
• You can put your custom logic in here
SpringByExample.com.ua
14
@ua_spring #uadevclub
18. Component model
SpringByExample.com.ua
18
@ua_spring #uadevclub
19. @Autowired
Spring proprietary annotation for property injection
Supports @Qualifier to select implementation by
name if more than one exists in context
Has required parameter to enforce dependency
loading
SpringByExample.com.ua
19
@ua_spring #uadevclub
25. SpEl
Stands for Spring Expression Language
Can be used in the xml context
Can be used in bean classes
SpringByExample.com.ua
25
@ua_spring #uadevclub
34. Spring AOP
Spring AOP defaults to using standard J2SE
dynamic proxies for AOP proxies. This enables any
interface (or set of interfaces) to be proxied.
Spring AOP can also use CGLIB proxies. This is
necessary to proxy classes, rather than interfaces
It is good practice to program to interfaces rather
than classes, business classes normally will
implement one or more business interfaces.
SpringByExample.com.ua
34
@ua_spring #uadevclub
35. AspectJ
Spring AOP is often uses the AspectJ declaration
style
AspectJ itself uses Load Time Weaving (LTW) to
modify the bean code according to Aspect logic
LTW could do much more than dynamic proxies but it
is more time-consuming operation. This means that
LTW has a performance drawback.
SpringByExample.com.ua
35
@ua_spring #uadevclub
38. Persistence with Spring
Building DAO
Spring Data
Embedded Datasources
JDBC vs ORM DAO’s
Integration testing with Spring
@Transactional & transactions with Spring
SpringByExample.com.ua
38
@ua_spring #uadevclub
41. Persistence layer
• Persistence service which has domain specific logic
Service
• Spring JDBCTemplate
• SessionFactory, EntityManagerFactory
Repository
(DAO) • Redis/Mongo template
• RDBMS (or NoSQL)
DB
SpringByExample.com.ua
41
@ua_spring #uadevclub
50. Persistence layer testing
Context loading in test
Environment abstraction and profiles usage
Transactional methods
Embedded data source could be used
SpringByExample.com.ua
50
@ua_spring #uadevclub
60. CRUD in one place
SpringByExample.com.ua
60
@ua_spring #uadevclub
61. REST in Spring MVC
Starting Spring 3.1.x
ContentNegotiatingViewResolver
@ResponseBody combined with produces
@RequestBody combined with consumes
SpringByExample.com.ua
61
@ua_spring #uadevclub
62. REST in Spring MVC
SpringByExample.com.ua
62
@ua_spring #uadevclub
63. Testing MVC
Starting from Spring 3.2
spring-test-mvc project
Server-side Spring MVC tests
New Spring Mocks
Different strategies
SpringByExample.com.ua
63
@ua_spring #uadevclub
66. Just to mention
Type conversion
Formatter SPI
SpringByExample.com.ua
66
@ua_spring #uadevclub
67. Just to mention
Type conversion
Formatter SPI
SpringByExample.com.ua
67
@ua_spring #uadevclub
68. Just to mention
Flash attributes and Redirect attributes
SpringByExample.com.ua
68
@ua_spring #uadevclub
69. Spring in 2012
SpringByExample.com.ua
69
@ua_spring #uadevclub
70. Just to mention
Spring Roo
Spring Hadoop
Spring Android
SpringByExample.com.ua
70
@ua_spring #uadevclub
71. Criticism
Every tool should be used only if you could not
solve your task without it – KISS
When a lot of stuff come out-of-the-box it is not
always good - YAGNI
When something is broken it is pain in the …
Open source but VMWare
SpringByExample.com.ua
71
@ua_spring #uadevclub