Download presentation
Presentation is loading. Please wait.
Published byMoris Jonah Newman Modified over 9 years ago
1
Spring core v3.x Prepared by: Nhan Le
2
History v3.0 Spring Expression Language Java based bean metadata v3.1 Cache Abstraction Bean Definition Profile Environment abstraction Test Context v3.2 Meta-annotations Global date & time format
3
Agenda IoC vs DI IOC Container Validation, Data Binding & Type conversion Spring Expression Language Testing Spring AOP Cache Abstraction
4
Inversion of control is a design principle that it decouples objects from specific lookup mechanisms and implementations of the objects it depends on Dependency injection is a form of IoC, where removes hard-coded dependencies and make it possible to change them at Compile time or Run Time IoC vs DI
5
Reduce coupling Both constructor and setter dependency injection reduce coupling. Improves testability Replace actual object with mock object which improves testability by writing simple JUnit tests which uses mock object. Flexibility As side benefit of loose coupling, because of DI you can replace non effective implementation with better one later Advantages of IoC
6
Dependencies Dependency Injection –Constructor based –Setter based –Interface Injection Dependency resolution process Circular dependencies
7
Dependencies type matching argument index argument name
8
IOC Container The interface org.springframework.context.ApplicationContext represents the Spring IOC container and is responsible for instantiating, configuring, and assembling the beans by reading configuration metadata Configuration Metadata - XML based - Annotation based - Java based
9
IOC – Bean Lifecycle
10
IOC – Bean Naming beans –Id, name and alias Instantiating beans –Constructor –Static factory –Method factory Inner beans –Inject able? –Scope?
11
Instantiating Beans Constructor Static Factory method Instance Factory method
12
Inner Beans 1)Can we inject Person class into others than outer class ? 2)Scope of Person class ? Can we change scope ?
13
IOC – Bean Lifecycle callbacks –@PostConstruct & @PreDestroy –InitializingBean & DisposableBean –Default initialization and destroy methods Callback order
14
IOC – Bean Aware interfaces
15
Testing UserService{ @Inject private UserDAO userDao;...... public boolean auth(String user, String pass){ String encryptedPass = encrypt(pass); User user = userDao.find(user, encryptedPass); if (user != null){ return true; } return false; }
16
Spring Expression Language ● Querying and manipulating an object graph at runtime ● Can be used independently ● Support implementation via – API –XML –Annotation
17
AOP ● Aspect-Oriented Programming ● Spring AOP ● Schema-based VS @AspectJ annotation type
18
AOP Concepts ● Aspect ● Join Point ● Advice ● Pointcut ● Introduction ● Target object ● AOP proxy ● Weaving
19
AOP Type of advice –Before advice –After returning advice –After throwing advice –After (finally) advice –Around advice
20
AOP Pointcut types (Spring AOP) –execution@target –within@args –target@annotation –args@within
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.