1. 12 Abril 2016 · Filipe Jorge
Enterprise Java Apps Summarizer #bué
2. What is it good for?
What is it?
✤ a set of abstract specifications with concrete implementations.
✤ has a huge API
✤ enables the developing and execution of applications
Java Enterprise Edition
✤ large scale
✤ multi-tiered !
✤ reliable
✤ secure
π
Network applications
3. Why is it good?
What is it?
✤ Spring is a lightweight and easy to use framework.
✤ Its heart is Dependency Injection, Inversion of Control and Aspect
Oriented Programming.
✤ Today it is the defacto standard for building enterprise Java applications.
Spring Framework
✤ Provides different modules and allow you to use any one based on your requirement.
✤ Makes it easy to swap components for another if you want different settings or
environments.
✤ Provides seamless integration with other frameworks, third party libraries etc.
✤ Needs much less boilerplate code and configurations.
✤ Deals with low-lever tasks like wiring dependencies and access databases.
In the end, gives you much more time to focus on business logic.
4. Why is it good? !
An analogy
✤ Dependency: A CD Player is useless without a CD with music on it. And if
they had a CD already in them, they would get boring very quickly…
✤ Injection: So CD Players are build allowing them use different CDs
That way you can inject a different CD each time and get different behavior
(music).
✤ Interfaces:
❖ The only requirement is that the CD must be compatible with the player.
You can't play a blue-ray disk in a 1992 CD player.
❖ The Player knows about CD's in general (how to read them, etc) - Interface
❖ But it doesn't know anything about a specific album - Implementation
Dependency Injection
5. What is it?
An analogy
You enter a restaurant, sit down and receive a menu.
When you decide what you’ll have you call the waiter and ask for what you want.
Then, the waiter scans your order, fetches the meal from the kitchen and serves you.
❖ You are only in charge of communicating your needs.
❖ An external entity does the leg work of detecting and resolving those needs
automatically.
Inversion of Control
✤ It creates the objects.
✤ Wire them together.
✤ Configure them.
✤ Manage their complete lifecycle, from creation till destruction.
IoC Container
6. Configuration
What is it?
✤ In short, it is the context that loads the configuration and then
Spring will start managing the beans.
Spring Context
Xml-bassed
Annotations-basedJava-based
7. !
What are they?
✤ A bean is an object that is instantiated, assembled, and
otherwise managed by a Spring IoC container.
✤ These beans are created with the configuration metadata that
you supply to the container.
Spring Beans
✤ What does a bean definition contain?
✤ How can we configure the instantiation of a bean?
✤ How to inject dependencies in a bean?
❖ (and what the rule of thumb?)
8. Collections Injection
!
✤ How can you inject Java Collection in Spring?
✤ singleton: single instance per Spring IoC container.
✤ prototype: any number of object instances.
✤ <list> allows duplicates.
✤ <set> without duplicates.
✤ <map> name and value can be of any type.
✤ <props> name and value are both Strings.
Bean Scope
✤ request: HTTP request.
✤ session: HTTP session.
✤ global-session: a global HTTP session.
Only valid in the context of a web-aware Spring ApplicationContext.
✤ What bean scopes do we learn? Explain them.
9. Lazy initialization
!
✤ Why is it bad?
✤ By default Spring instantiates and configures all singleton
beans as part of the initialization process. This way we
immediately detect errors.
10. “Once Upon a Time in JVM”
✤ Instantiate - First the spring container finds the bean's definition from the XML file and instantiates the
bean..
✤ Populate properties - Using the dependency injection, spring populates all of the properties as specified
in the bean definition..
✤ Set Bean Name - If the bean implements BeanNameAware interface, spring passes the bean's id to
setBeanName() method.
✤ Set Bean factory - If Bean implements BeanFactoryAware interface, spring passes the beanFactory to
setBeanFactory() method.
✤ Pre Initialization - Also called postprocess of bean. If there are any bean BeanPostProcessors associated
with the bean, Spring calls postProcesserBeforeInitialization() method.
✤ Initialize beans - If the bean implements IntializingBean,its afterPropertySet() method is called. If the
bean has init method declaration, the specified initialization method is called.
✤ Post Initialization - If there are any BeanPostProcessors associated with the bean, their
postProcessAfterInitialization() methods will be called.
✤ Ready to use - Now the bean is ready to use by the application.
✤ Destroy - If the bean implements DisposableBean , it will call the destroy() method .
Bean Lifecycle
11. 12 Abril 2016 · Filipe Jorge
Entreprise Java Apps
Summarizer #bué