Basics Flashcards
(21 cards)
What is Spring?
An open source framework that makes the java development easier
How does spring benefits java development by making it easier?
- Lightweight and minimally invasive development of Pojos
- Loose coupling through DI
- Declarative programming through aspects and common conventions
- Removes boiler plate codes
How it unleashes the power of POJOS?
Spring doesnt mandate the classes to implement/extend spring specific interface/classes. Other frameworks such as Struts makes you compulsory to implement their specific interfces
What is dependency injection
Traditionally, each object gets its dependencies of its own. It makes the objects tightly bound with one another.
This DI, one object is injected with other at comple time through a third part, which is spring here - Based on configuration
How does spring framework works?
An application context loads the beans defined and wire them together according to the configuration
How does java knows which application context to load?
In main method, the context to be loaded is described
What is AOP?
Enables us to capture functionality that is used thrughout the application in reusable components.
Its seperation of concersns
What are the normal cross-cutting concerns?
- Security
- Transactions
- Logger
Generic explanation of AOP?
Using AOP, system-wide concerns blanket the components they impact. This leaves the application components to focus on their specific business functionality
How spring eliminates boiler plate code?
by using Templates.Eg.., Spring JDBCTemplates eliminates the boiler plate code for JDBC Connections
Where does the application objects live in Spring based application?
Spring container
Which is the core of the Spring framework?
Spring container
What are the two types of Spring framework?
Bean factories - simplest of containers, basic support of DI
Application contexts - Application framework services
What are the different application context?
- AnnotationConfigApplicationContext
- ClassPathXMLApplicationContext
- AnnotationConfigWebApplicationContext
- FileSystemXMLApplicationContext
- XMLApplicationContext
Where does the ClassPathXmlApplicationContext looks for bean configuration xml?
In the Class path
Life cycle of beans?
- Instantiate
- Populateproperties
- BeanNameAware’s (setBeanName)
- BeanFactoryAware’s (setBeanFactory)
- ApplicationContextAware’s (setApplicationContext)
- Pre-Initialization (beanPreProcessor)
- InitilaizingBean’s (afterPropertySet)
- custom-init method
- beanPostProcesseor
Bean gets life - disposableBean (destroy method)
- Calling custom destroy method
11.
what are the three ways of bean configuration?
- Explicit configuation through XML
- Explicit configuration by java
- Let beans automatically configure
How can we wire collections eg.. List?
Dilli
DilliGanesh
If we want to inject a list of bean references, then replace with
Choosing between constructor injection and property injection?
Hard dependencies - constructor injection
Optional dependencies - property injection
What attribute does Spring provides for resolving environment specific details?
@profile(“prod”) -> java config
-> xml config
What are the different scopes of beans in spring?
- Singleton- One instance of bean for entire application
- Prototype- One instance of the bean is created every time the bean is injected
into or retrieved from the Spring application context. - Session - One instance of the bean created for each session in Web application
- One instance of the bean created for each request in web application